PDA

View Full Version : Subscript out of range: Do While Cells(s2, 2) And Cells(s2 + 1, 2) <> "end"



lks55
03-23-2016, 10:21 AM
hi

I have a document and sometimes there is a line empty. The loop should stop when 2 lines in a row are empty. I tried this:


Do While Cells(s2, 2) And Cells(s2 + 1, 2) <> "end"

But it tells me "Subscript out of range". I looked up some pages in google, but haven't found something helpful. Has anybody an idea for my problem or an other solution?

Best Regards

Paul_Hossler
03-23-2016, 01:04 PM
I'm guessing that something like this might work



Option Explicit

Sub test()
Dim s2 As Long
s2 = 1

Do
MsgBox Cells(s2, 2).Address
s2 = s2 + 1
Loop Until Len(Cells(s2, 2)) = 0 And Len(Cells(s2 + 1, 2)) = 0

End Sub