Selecting Ranges using Variables

D

DG

I currently have Sheet2 active in this example:

Sub TestIt()
Dim Line as Integer

Line = 8
x = 1

While Cells(x,1) <> ""
Sheets("Sheet1").Range("A" & Line & ":K" & Line).Select
x = x + 1
Wend
End Sub

I get an error on the Select statement "Select Method of Range Class
Failed".

I am trying to select Range("ALine:KLine") where Line is the variable.

Any help would be great.

DG
 
B

BigJimmer

You need to have "Sheet1" active to select the range. Try this...

Sub TestIt()
Dim Line As Integer
Dim x as Integer

Line = 8
x = 1

Worksheets("Sheet1").Activate

While Worksheets("Sheet2").Cells(x, 1) <> ""
Worksheets("Sheet1").Range("A8:K8").Select
x = x + 1
Wend
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top