Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to refer to a range of cells in excel from within Access 1

Status
Not open for further replies.

davikokar

Technical User
May 13, 2004
523
IT
Hallo,

I'm using this code to refer to a range of cells in an excel sheet from Access:

Code:
Sht.Range(Cells(1, 1), Cells(uRow - 1, 1)).Interior.ColorIndex = "6"

where Sht is:

Code:
Set Sht = xlApp.ActiveWorkbook.Sheets(2)

and uRow is an integer variable

I also tried to use this:
Code:
Sht.Range(.Cells(1, 1), .Cells(uRow - 1, 1)).Interior.ColorIndex = "6"

but without success...

it is strange because if I use the same sintax within a "WITH/END WITH" sentence it does work:

Code:
With Sht
    .Range(.Cells(1, 1), .Cells(uRow - 1, 1)).Interior.ColorIndex = "6"
End With

Any ideas? thanks
 
Hi!

In this case you need the dot operator because Cells is a property of a sheet, that is why your first line of code doesn't work. The second line doesn't work because the .Cells isn't related to an object, which is also why the third line of code does work. An alternative is:

Sht.Range("A1:A" & Format(uRow - 1))

hth


Jeff Bridgham
Purdue University
Graduate School
Data Analyst
 
thanks jebry for clarifications and suggestion
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top