PDA

View Full Version : Compile Error



sasha
02-12-2011, 06:25 AM
Hi People,

I'm pretty new to writing code and have an issue with one piece for a long macro I'm writing. The section is:

For i = 0 To NoCols
For j = 1 To NoRows

If Sheets(InputSheet).Cells(startrow + j, startcol + i) = "" Then
MsgBox ("Error in Data - Blank Cell")
End
End If

tempstr = Cells(startrow + j, startcol + i).Text
Count = 1
Do While Count <= Len(tempstr)
If Mid(tempstr, Count, 1) = "," Then
MsgBox ("Error in Data - Comma Present")
End
End If
Count = Count + 1
Loop

Next i
Next j


The error I get is 'Invalid next control reference'

Any idea why that is because it looks the same as alot of similar stuff thats worked fine for me before.

Thanks in advance

Bob Phillips
02-12-2011, 06:33 AM
Which row?

sasha
02-12-2011, 06:36 AM
This is if I go to run the macro by pressing F8 one step at a time, it just jumps straight to that error

sasha
02-12-2011, 06:38 AM
Actually I've solved it now, the j needed to come before the i

Thanks

shrivallabha
02-12-2011, 06:39 AM
Welcome to VBAX!

Try checking your code using Step Mode (Pressing F8). Also:
Sheets(InputSheet)
should be:
Sheets("InputSheet")

Use the technique mentioned above and see where the code fails you. All the best.

Bob Phillips
02-12-2011, 06:45 AM
Actually I've solved it now, the j needed to come before the i

Thanks

Oh yeah, didn't notice that :)