PDA

View Full Version : picking range from "A1" to variable



progfrog
07-16-2010, 03:53 AM
Hi guys!
I'm stuck in a very stupid thing- i'm trying to loop through this range

For Each c In Worksheets("Sheet1").Range("A1: & LastCell &").Cells

If c.Value = value1 Then
value2 = .Cells(c.Row, "B").Value
MsgBox (value2)
End If
Next c


I have this variable
LastCell=A17

And I would like to put it instead of the explicit cell but i keep getting erros- how can I use varible ina a range?

what is the right syntax for that?

thanx!

Bob Phillips
07-16-2010, 04:40 AM
For Each c In Worksheets("Sheet1").Range("A1: & LastCell).Cells

If c.Value = value1 Then
value2 = .Cells(c.Row, "B").Value
MsgBox (value2)
End If
Next c