View Full Version : Solved: Why using Range() works but Cells() doesn't??

11-02-2010, 09:57 AM

I need to select a range but needed to define a dynamic variable as things change. My variable is call endcol_d and it is the column I need to put in the range.
So I have

basebook.Sheets("Protect Population").Range(Cells(5, endcol_d), Cells(5, endcol_d + 1)).Select

But that doesn't work. It gives and error. But when I test it using Range("") for one instance it works. basebook.Sheets("Protect Population").Range("B5:C5").Select
How can I make it work using Cells??

Appreciate any help!!

Bob Phillips
11-02-2010, 11:43 AM
You need to dot qualify everything

With basebook.Sheets("Protect Population")

.Range(.Cells(5, endcol_d), .Cells(5, endcol_d + 1)).Select
End With

11-02-2010, 01:57 PM
Ah that fixed it! Thanks!!

11-13-2010, 06:58 AM
endcol_d = 4
ThisWorkbook.Sheets(1).Range(Cells(5, endcol_d), Cells(5, endcol_d + 1)).Select

11-13-2010, 08:25 AM
You can also use Resize
basebook.Sheets("Protect Population").Cells(5, endcol_d).Resize(,2).Select