Is there a way to set the order by which a process searches a sheet for information? I.E, search from the bottom up as opposed to the top down?
I have code which searches sheets for a date and copies the row with that date to another sheet, it does it from the top down, so if there happen to be two rows with the same date on the same sheet, the first date it hits is the one it takes, then it moves to the next sheet, but what I need is for it to take the more recent entry, for instance if there were more than one date entered but each had different times, the second row with the same date would be the one with the more recent time. So, if the search was conducted from the bottom up, it would hit take the correct row needed.
This is my current code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address <> [G3].Address Then Exit Sub
If Not IsDate(Target.Value) Then
MsgBox "Value entered into " & Target.Address & " is not a date"
If Target.Value > 0 Then
Sheets("Hidden Data").Range("A1").Value = Target.Value
Dim ws As Worksheet
Dim fnd As Range
Application.ScreenUpdating = False
Application.EnableEvents = False
For Each ws In ThisWorkbook.Worksheets
If ws.Name <> "Status Report" And ws.Name <> "Hidden Data" Then
Set fnd = ws.Range("A:A").Find(Target.Value, , xlValues, xlWhole)
If fnd Is Nothing Then
Sheets("Hidden Data").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).Value = "'"
If Not fnd Is Nothing Then
Sheets("Hidden Data").Cells(Rows.Count, "A").End(xlUp).Offset(1, 0).PasteSpecial xlPasteValues
Application.ScreenUpdating = True
Application.EnableEvents = True
I tried messing with a code like:
Range("A1:H4").Sort Key1:=Range("A2"), Order1:=xlDescending, Key2:=Range( _
"B2"), Order2:=xlDescending, Header:=xlGuess, OrderCustom:=1, MatchCase _
:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal, _
To try to automatically change the sorting of the sheet before the process of searching the sheets was done, but couldn't find the correct way to get it implimented with the first bit of code.
Anyhow, first I just need to know if its possible at all, thus the lower points, will upgrade to 500 if someone can actually help me figure out how to get this to somehow work.
The goal: using first bit of code, grab not only the row with the correct date, but the most recent time as well.
Thank you all for your help.