ok that sounds great but I'm a little tired as its 1 am here.
how does it search each row in column S to find the those that have a 1 to run what you have posted?[
/QUOTE]
Just loop the first argument instead of the second one....
Code:Col = "S" ' The second argument to Cells can be either a column number or column letter LastRowInS = Cells(Rows.Count, Col).End(xlUp).Row For i = 1 To LastRowInS If Cells(i, Col).Value = 1 Then ' Whatever End If Next
If you are testing like I did...Also if I tell it as a test to run line 48 it picks up cells that have text in them as empty does that code work also for text or just values?
then the only way it could do that is if the cell had something in it... perhaps a blank space? Without seeing your workbook, it is hard to say.Code:If Cells(RowNumber, i).Value = "" Then
[FONT=Verdana][SIZE=2][COLOR=#333333]Sub Mandatory()[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]col = "S"[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]LastRowInS = Cells(Rows.Count, col).End(x1Up).Row[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]For i = 1 To LastRowInS[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] If Cells(i, col).Value = 1 Then[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] For x = 4 To 17[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] If Cells(RowNumber, x).Value = "" Then[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Application.Goto Cells(RowNumber, x)[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] MsgBox "Mandatory feild not completed"[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Cancel = True[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Exit For[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Next[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]Next[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]End Sub[/COLOR][/SIZE][/FONT]
comes up witha debug error on LastRowInS = Cells(Rows.count, Col).Enx(x1Up.Row
Code:[FONT=Verdana][SIZE=2][COLOR=#333333]Sub Mandatory()[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333]col = "S"[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333]LastRowInS = Cells(Rows.Count, col).End([/COLOR][SIZE=3][B][COLOR=#B22222]x1Up[/COLOR][/B][/SIZE][COLOR=#333333]).Row[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333]For i = 1 To LastRowInS[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] If Cells(i, col).Value = 1 Then[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] For x = 4 To 17[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] If Cells(RowNumber, x).Value = "" Then[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] Application.Goto Cells(RowNumber, x)[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] MsgBox "Mandatory feild not completed"[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] Cancel = True[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] Exit For[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] Next[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333]Next[/COLOR][/SIZE][/FONT] [FONT=Verdana][SIZE=2][COLOR=#333333]End Sub[/COLOR][/SIZE][/FONT]
ok now it blows up in the IfCells(RowNumber, X).Value = ""Then
I'm starting to think it would be quicker just to write out 40 if statements for each possible row it could be in.
[FONT=Verdana][SIZE=2][COLOR=#333333]Sub Mandatory()[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]col = "S"[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]LastRowInS = Cells(Rows.Count, col).End(x1Up).Row[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]For i = 1 To LastRowInS[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] If Cells(i, col).Value = 1 Then[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] For x = 4 To 17[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] If Cells([/COLOR][SIZE=3][B][COLOR=#B22222]RowNumber[/COLOR][/B][/SIZE][COLOR=#333333], x).Value = "" Then[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Application.Goto Cells(RowNumber, x)[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] MsgBox "Mandatory feild not completed"[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Cancel = True[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Exit For[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] Next[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333] End If[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]Next[/COLOR][/SIZE][/FONT]
[FONT=Verdana][SIZE=2][COLOR=#333333]End Sub[/COLOR][/SIZE][/FONT]
and we end up back where we started the rownumber is unknown when writing the code as I don't know which rows will have the 1 in it and that will change as the report is used.
Sorry if i have missed something else but it now looks like I will be not getting any sleep tonight as this report is due in about 5 hours