VBA Nested if statement problems

  • Goal: Ask question, answering with YES of NO.

    • When pressing YES, macro needs to check if there are no values inside range E2:E202 < 0:

      • if values in range are < 0: macro needs to give a warning and quit question
      • if all values =>0: macro needs to execute the Bold vba part

    • When pressing NO, macro quits question

    My not working code below.
    Can someone please help me correct this code please?

    Sub knopOpslagenUren()

    Dim antwoord As Integer
    Dim vraag As String

    vraag = "Bent u zeker dat alle meterstanden correct ingevuld zijn? - Er mogen geen rode kruisjes aanwezig zijn. -"
    antwoord = MsgBox(vraag, vbYesNo + vbQuestion, "Goedemorgen")

    If antwoord = vbNo Then
    Exit Sub

    If antwoord = vbYes Then

    Dim interval As Range
    Dim kolom As Range

    Set kolom = Range("F3:F202")
    For Each interval In kolom
    With interval
    If .Value < 0 Then
    MsgBox "Er zijn nog foutief ingevulde waarden. Gelieve dit te controleren a.u.b.", vbCritical, "Goedemorgen"
    Exit Sub

    Dim meterstanden As Worksheet
    Dim database As Worksheet
    Dim volgendekolom As Long

    Set meterstanden = Sheets("iUren")
    Set database = Sheets("dbTellers")
    volgendekolom = database.Cells(2, 1).End(xlToRight).Column
    If volgendekolom > 1 Then
    volgendekolom = volgendekolom + 1
    End If

    database.Cells(2, volgendekolom).PasteSpecial xlPasteValues
    Application.CutCopyMode = False
    Application.ScreenUpdating = True

    End If
    End With

    End Sub

  • Does this work:

    You can say "THANK YOU" for help received by clicking the "Like" icon in the bottom right corner of the helper's post.
    Practice makes perfect. I am very far from perfect so I'm still practising.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!