Easy VBA question: range control
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 |
Easy VBA question: range control
Saaawwwwry.... that should read "last non-empty cell".
|
Easy VBA question: range control
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 -- Regards, Tom Ogilvy "J.B. Bobbitt" wrote in message nk.net... Saaawwwwry.... that should read "last non-empty cell". |
Easy VBA question: range control
This group is too cool! I hope I can be of some help.
Thanks. -jbb "Tom Ogilvy" wrote in message ... 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 -- Regards, Tom Ogilvy "J.B. Bobbitt" wrote in message nk.net... Saaawwwwry.... that should read "last non-empty cell". |
All times are GMT +1. The time now is 10:00 AM. |
Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com