If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Excel > Data/String into an Excel Cell using VB

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-05-10, 09:53
72camaross 72camaross is offline
Registered User
 
Join Date: Nov 2009
Location: Canada
Posts: 11
Data/String into an Excel Cell using VB

Hey guys,

I'm trying to get string/numbers into specific excel cells using VB but can't seem to find the right calls anywhere. Any help would be appreciated!

Thanks,
JD
Reply With Quote
  #2 (permalink)  
Old 01-05-10, 10:23
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 477
The path through the Excel object model would be:
Code:
Excel.Application.Workbooks("MyWorkbook.xls").Worksheets("Sheet1").Range("A1").Value = "hello"
The depth of the qualification depends on how and where you are automating the process from.

Does that help?
__________________
Colin

My Excel articles

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
  #3 (permalink)  
Old 01-05-10, 12:16
72camaross 72camaross is offline
Registered User
 
Join Date: Nov 2009
Location: Canada
Posts: 11
Thanks Colin_L!

Worked like a charm.

Yeah I couldn't wrap my head around the Range thing and I saw a couple other posts on other sites using worksheet.cells(icol,irow) = "hello" type stuff which I couldn't get to work.

Now I can relax my brain from that and focus on more important things like the USA / Canada game tonight...
Reply With Quote
  #4 (permalink)  
Old 01-05-10, 14:03
Colin Legg Colin Legg is offline
Registered User
 
Join Date: Sep 2008
Location: London, UK
Posts: 477
Hi,

For VBA/6/S purposes, the worksheet.cells property is similar to the worksheet.range property in that they both return a reference to a range object. (There is no Cell object).

The following are both the equivalent of each other:
Code:
Excel.Application.Workbooks("MyWorkbook.xls").Worksheets("Sheet1").Range("A1").Value = "hello"

Excel.Application.Workbooks("MyWorkbook.xls").Worksheets("Sheet1").Cells(1,1).Value = "hello"
The worksheet.cells property is particular useful when you need the column reference enumerated (1 instead of "A"), such as in a For.. Next loop.

Hope that helps...
__________________
Colin

My Excel articles

Other tutorials:
Array Formulas | Deleting Rows with VBA
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On