Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2009
    Location
    Canada
    Posts
    11

    Unanswered: 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

  2. #2
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    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?

  3. #3
    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...

  4. #4
    Join Date
    Sep 2008
    Location
    London, UK
    Posts
    511
    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...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •