VBA Date Problem

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi,

I have a problem with this code below. The code should load data 5 days before the date from the table in column "E", instead it is loading all of the data. I have also provided a screenshot in the link. Please, if anyone can help, it'll be helpful.


Code:
Private Sub UserForm_Initialize()

    Dim LRow        As Integer
    Dim LDiff       As Integer
    Dim LDays       As Integer

     LRow = 4   'start at row 2
    LDays = 5   'Warning - Number of days to check for expiration

    ThisWorkbook.Activate

    With ListView2
        .HideColumnHeaders = True
        .Appearance = ccFlat
        .ColumnHeaders.Clear
        .View = lvwReport
        .FullRowSelect = False
        .HideSelection = True
        .Gridlines = True
    
        .ColumnHeaders.Add , , "Due Since", 110
        .ColumnHeaders.Add , , "Clients-Nr", 72, Alignment:=1
        .ColumnHeaders.Add , , "Clients-Nr", 0, Alignment:=1
    End With
    
        ' Adds data      ** Sheet11 = Sheets("Rent_Pay_DB")     Sheets("Rent_Pay_DB").Cells(Row, 12) > "0.00"
        ListView2.ListItems.Clear
        row = 4
    
        Do Until Sheets("Rent_Pay_DB").Cells(row, 5) = ""
    
'    If Len(Sheets("Rent_Pay_DB").Range("E" & LRow).Value) > 0 Then
            
            LDiff = DateDiff("d", Date, Sheets("Rent_Pay_DB").Range("E" & LRow).Value)
            If (LDiff < 0) And (LDiff <= LDays) And (Sheets("Rent_Pay_DB").Cells(row, 13) > "0.00") Then
            
            Set Li = ListView2.ListItems.Add(Text:=Format(Sheet11.Cells(row, "A").Value, "General"))   'Property Address
                         Li.ListSubItems.Add Text:=Format(Sheet11.Cells(row, "M").Value, "#,##0.00")
                         Li.ListSubItems.Add Text:=Format(Sheet11.Cells(row, "E").Value, "m/d/yyyy")
            End If
'    End If
            row = row + 1
     
        Loop

End Sub

https://imgur.com/IWZ140c

Best Regards

 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,875
Messages
6,122,044
Members
449,063
Latest member
ak94

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top