Finding Date in Listview

JarekM

Board Regular
Joined
Nov 13, 2018
Messages
86
Hi,
Is there anyone that can show me how to find in listview control column 2 the earliest date and populate it in textbox 1, and the latest date into textbox 2.

Thank you to anyone that can help me.
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
This works for me

Code:
Dim Latest, Earliest, r, Itm
       
With Me.ListView1
        Latest = .ListItems(1).SubItems(1)
        Earliest = Latest
       
        For r = 1 To .ListItems.Count
            Itm = .ListItems(r).SubItems(1)
            If Itm > Latest Then Latest = Itm
            If Itm < Earliest Then Earliest = Itm
        Next r
    
        Me.TextBox1 = Earliest
        Me.TextBox2 = Latest
        
End With
 
Upvote 0
Thank you for your response.
When I entered your code an error showed up instead, on the second line of your code (Latest = .ListItems(1).SubItems(1) - It was highlighted in yellow), so I changed the declaration as seen below. The code has started to work, but I am not an expert in VBA and I just want to see if you can check it and make sure that it is fine or if there are any small changes that are needed because I don't want to have any errors show up in the future.

Here is the code that I used:

Code:
Dim Latest      As Date
Dim Earliest    As Date
Dim r, Itm

With Me.ListView1
      Latest = .ListItems(1).SubItems(1)
    Earliest = Latest

    For r = 1 To .ListItems.Count
        Itm = .ListItems(r).SubItems(1)
        If Itm > Latest Then Latest = Itm
        If Itm < Earliest Then Earliest = Itm
    Next r

    Me.txt_dataINI = Earliest
    Me.txt_dataFIM = Latest
End With

End Sub

Thank you
 
Upvote 0
thanks for the feedback
glad that you found a way to make it work for you
:beerchug:
 
Upvote 0

Forum statistics

Threads
1,223,879
Messages
6,175,147
Members
452,615
Latest member
bogeys2birdies

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