Update value on another new line of row if another entry has been made for same ID number

hsolanki

Board Regular
Joined
Jan 16, 2020
Messages
204
Office Version
  1. 2010
Platform
  1. Windows
Hi i have a code whereby it works fine for when it finds the Staff ID for 1st Job allocated then it will update timestamp on the same line in column "M" when list has been selected from list box however when i try to update the another new line of row for the same person with different Job number it will still again update first Job line of row and not the 2nd Job line of row when i tried to add the 3rd Job.

me.lstselector.list(x,3) - it is the Staff ID in column G
me.lstselector.list(x,2) - it is the Job number in column F

i need code to find using Job number and staff ID, when matches it both then to updates time on same row every time in column M

here its the code

VBA Code:

dim findvalue

Sheet1.Unprotect codePassword:="1234"
lCol = Me.lstSelector.List(x, 3)
Set findvalue = Sheet1.Range("G:G").Find(What:=lCol, LookIn:=xlValues).Offset(0, -2)
findvalue.Offset(0, 8).Value = Format(Now, "HH:MM:SS")
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Maybe this:
VBA Code:
Dim adr As String
Sheet1.Unprotect codePassword:="1234"
lCol = Me.lstSelector.List(x, 3)
Set findvalue = Sheet1.Range("G:G").Find(What:=lCol, LookIn:=xlValues)
    If Not findvalue Is Nothing Then
        adr = findvalue.Address
        Do
            If findvalue.Offset(, -1).Value = Me.lstlelector(x, 2) Then
                findvalue.Offset(0, 6).Value = Format(Now, "HH:MM:SS")
                Exit Do
            End If
            Set findvalue = Sheet1.Range("G:G").FindNext(findvalue)
        Loop While findvalue.Address <> adr
        Set findvalue = Nothing
    End If

Note that I change the findvalue range to remain in column G. If you were using it elsewhere in the code for another purpose you will need to add the offset(, -2) to each place it is used. But if you change it back in this snippet, then the FindNext function will not work.
 
Last edited:
Upvote 0
Hi thank you for your reply and response however i get an error mistypes on below line

VBA Code:

If findvalue.Offset(, -1).Value = Me.lstselector(x, 2) Then
 
Upvote 0
My error in typing instead of copying.
Should be:
VBA Code:
If findvalue.Offset(, -1).Value = Me.lstselector.List(x, 2) Then
 
Upvote 0
Hi Thank you very much for all your help. it worked as i excepted :).
 
Upvote 0

Forum statistics

Threads
1,214,833
Messages
6,121,868
Members
449,053
Latest member
Mesh

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