Sub printF()
Dim i As Long, printFrom As Long, printTo As Long
printFrom = Sheet3.Range("AF6").Value
printTo = Sheet3.Range("AF7").Value
For i = printFrom To printTo
If (Sheet3.Range("AE20").Value > 0) 'This check
Sheet3.Range("AF4").Value = i
Sheet3.PrintOut Preview:=False
Next i
End Sub
It works fine but if I try to input the checking value if crashes.
CodePudding user response:
If you are just asking how to use an If
block....
For i = printFrom To printTo
If Sheet3.Range("AE20").Value > 0 Then
Sheet3.Range("AF4").Value = i
Sheet3.PrintOut Preview:=False
End If
Next i
CodePudding user response:
You possibly have to add an error check with IsError before you do a comparision.
If Not IsError(Sheet3.Range("AE20")) Then
If (Sheet3.Range("AE20").Value > 0) Then
Sheet3.Range("AF4").Value = i
Sheet3.PrintOut Preview:=False
End If
End If
If you have an error value in the cell the comparision Sheet3.Range("AE20").Value > 0
will run into a run time error 13