Consulting

Results 1 to 3 of 3

Thread: Run code under specific criteria

  1. #1
    VBAX Regular
    Joined
    Oct 2012
    Posts
    85
    Location

    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]

  2. #2
    Just insert:

    [VBA]If Not IsDate(Range("A1").Text) Then Exit Sub[/VBA]


    directly after your second Dim statement.
    Regards,

    Jan Karel Pieterse
    Excel MVP jkp-ads.com

  3. #3
    VBAX Regular
    Joined
    Oct 2012
    Posts
    85
    Location
    Great, thank you!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •