-
Run code under specific criteria
How can I make it so this code only runs IF cell A9 has a date in it? If cell A9 is blank, then I would like to not run this code because an error occurs.
[VBA]Sub BlockQuantityfidelity()
Const FORMULA_SUM As String = _
"=IF($G9="""","""",SUMPRODUCT(--($G$9:$G$<lastrow>=$G9),--($H$9:$H$<lastrow>=$H9),$AN$9:$AN$<lastrow>))"
Dim lastrow As Long
With ActiveSheet
lastrow = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("AC9").Resize(lastrow - 8).Formula = Replace(FORMULA_SUM, "<lastrow>", lastrow)
End With
End Sub[/VBA]
-
Just insert:
[VBA]If Not IsDate(Range("A1").Text) Then Exit Sub[/VBA]
directly after your second Dim statement.
-
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules