dimanche 25 février 2018

If date greater than or equal then function

Public DateRng As String

Private Sub DateLookup()

'Dim ColCnt As Integer

'Prompt Date to look for
  DateRng = InputBox("Insert date in format dd/mm/yy", "User date", Format(Now(), "dd/mm/yy"))
  If IsDate(DateRng) Then
    DateRng = Format(CDate(DateRng), "dd/mm/yy")
    ColumnDateCheck
'    MsgBox DateRng
  Else
    MsgBox "Wrong date format"
    Exit Sub
  End If



End Sub

Private Sub ColumnDateCheck()

    For C = 3 To 29
        If Cells(C, 2) >= DateRng Then
            'Function
            Cells(C, 5) = Cells(C, 3) + Cells(C, 4)

        End If
    Next

End Sub

Data in which code is performing on

Test Sheet

Not having error executing code but function is not working as intended. It executes function in a mess without any pattern behind it. Can't understand output.

  1. InputBox in DateLookup sub prompts for date
  2. If entry is valid, call out ColumnDateCheck Sub
  3. Look for date entered in column B from Row 3 to 29. If date is greater or equal to, adds column C & D in Column E.

Aucun commentaire:

Enregistrer un commentaire