Easy VBA question: range control

  • Thread starter Thread starter J.B. Bobbitt
  • Start date Start date
J

J.B. Bobbitt

I know this sounds easy, but I'm new to VBA and I haven't been able to solve
it successfully:

In a VBA IF-THEN-ELSE statement, how do I specify a range that includes
column A from cell A2 to the last non-empty column?

Here's my existing code:

Sub aaaa
Column ("A:A").Select
For Each cell in Selection
If cell.Value > 0 Then cell.Offset(0, 1) = "string1"
Else cell.Offset(0, 1) = "string2"
End If
Next Cell
End Sub

This code works, but fills the entire Offset column, all 65,000+ rows. I
only want to to fill the first 1000-1500 rows, depending on how many rows in
the worksheet have data.

Thanks in advance.

-jbb
 
Sub aaaa
Dim cell as Range, rng as Range
set rng = Range(cells(1,1),Cells(rows.count,1).End(xlup))
For Each cell in rng
If cell.Value > 0 Then
cell.Offset(0, 1) = "string1"
Else
cell.Offset(0, 1) = "string2"
End If
Next Cell
End Sub
 
Back
Top