How to isolate a specific row on a sheet using three variables?

chipsworld

Board Regular
Joined
May 23, 2019
Messages
169
Office Version
  1. 365
Good day all,
Need your help once again.
I found the base code from the below on the web and thought it would work, but apparently I need some morre help.

The original code worked great for two variables, but in order to do what I need to do, I need a third.

The issue is if the second variable occurs more than once, it will always go to that instance and not look for another one.

Here is what I have...I'm sure someone out there can make sense of it.
The parts in red are my add in attempt to include a third variable.
As you can probably tell, the whole idea is to capture the date and time someone returns an item and put that date/time into the line where they checked it out.

The code works beautifully without my changes if the item being checked out is only checked out once. ITs that second, third, etc that kill it...

VBA Code:
Private Sub INBOUND()
Dim rngFound As Range
Dim strFirst As String
Dim strNam As String
Dim strAsset As String
Dim rw As Long
Dim timestmp As String
Dim ws As Worksheet
Dim strtimo As String

    
    Set ws = ThisWorkbook.Worksheets("ASSET Loging")
    timestmp = Now
    strNam = Me.txtnam.Value
    strAsset = Me.cmbasstype.Value
    strtimo = Me.txtdat.Value
    
    With ws
    Set rngFound = .Columns("C").Find(strNam, Cells(Rows.Count, "C"), xlValues, xlWhole)
    If Not rngFound Is Nothing Then
        strFirst = rngFound.Address
        
        Do
            If LCase(.Cells(rngFound.Row, "A").Text) = LCase(strAsset) [B][COLOR=rgb(226, 80, 65)]And LCase(.Cells(rngFound.Row, "E").Text) = LCase(strtimo) [/COLOR][/B]Then
                
                        'Found a match
                        rw = rngFound.Row
                        If ws.Cells(rw, "F").Value = "" Then
                        ws.Cells(rw, "F").Value = timestmp
                        Else: MsgBox "This item has already been marked as returned!", vbOKOnly
                        Exit Sub
                        End If

            End If
            Set rngFound = .Columns("C").Find(strNam, rngFound, xlValues, xlWhole)
        Loop While rngFound.Address <> strFirst
    End If
    End With
    
    MsgBox "Item has been marked as received!", vbOKOnly
    
    Set rngFound = Nothing

End Sub
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
Try changing this snippet
VBA Code:
            End If
            Set rngFound = .Columns("C").Find(strNam, rngFound, xlValues, xlWhole)
        Loop While rngFound.Address <> strFirst

into this
Rich (BB code):
            End If
            Set rngFound = .FindNext(rngFound)
        Loop While rngFound.Address <> strFirst
 
Upvote 0
Try changing this snippet
VBA Code:
            End If
            Set rngFound = .Columns("C").Find(strNam, rngFound, xlValues, xlWhole)
        Loop While rngFound.Address <> strFirst

into this
Rich (BB code):
            End If
            Set rngFound = .FindNext(rngFound)
        Loop While rngFound.Address <> strFirst
Nope....gives me:

Compile error:
Method or Data member not found.

Open to any other ideas...
 
Upvote 0
How about
VBA Code:
Set rngFound = .Columns("C").FindNext(rngFound)
 
Upvote 0
Could the fact that the third variable I am tryin to match is a date and time? Should I be using something other than LCase?
Are you getting an error and if so, on which line and what does it say?
 
Upvote 0
Date and time representations come from numerical values (vartype Double). Comparing a number against text will error.
 
Upvote 0
A closer look at your code tells me that you are only working with variables of vartype String, even though you are working with date and time. If you're able to tell us what kind of data you have in successively the columns A, C, E and F and what you exactly are trying to achieve, we probably may amend your code in a way it's going to do what you're looking for.
 
Upvote 0
OK...here is the breakdown...

"A" = Asset type (Truck, Van, Computer, etc)
"B" = Serial Number (Not all Assets have serials)
"C" = Last name, First (Set from a vlookup compared to an ID number which is scanned (Column D)
"D" = EMPLOYEE # (From badge scan)
"E" = Date time OUT (using NOW to set that part)
"F" = Date time IN (Again, using NOW to set that value)

Trying to look up using Name, then asset, then datetime.

The reason I am adding in the third variable is because if a person checks out the same asset twice, the current code will not find the second, third, etc instance. It will only find the first one.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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