Use lookup to enter value in the adjacent cell

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
1,075
Office Version
  1. 2019
Platform
  1. Windows
I have a user form label that displays an ID tag. This ID Tag is also in a list in column AA. I would like to look up the Userform ID Tag in the list in Column AA and enter a number value adjacent to the ID Tag in column AB in VBA. Can someone assist a VBA code that will accomplish this task?

Thank you kindly for assistance.
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
You left out a lot of details.
Like the name of the Userform Label.
What value you want entered in Column AB

This script assumes your label is named label1

And you want the value 3 entered into column AB

All this would be on the active sheet.

Try this:

Code:
Private Sub CommandButton1_Click()
'Modified  7/13/2019  2:56:42 AM  EDT
Dim SearchString As String
Dim SearchRange As Range
SearchString = Label1.Caption
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "AA").End(xlUp).Row
Set SearchRange = Range("AA1:AA" & Lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If SearchRange Is Nothing Then MsgBox SearchString & "  Not Found": Exit Sub
SearchRange.Offset(0, 1).Value = 3
End Sub
 
Upvote 0
Thank you greatly M.A.I.T. It script works as expected. My apologies for too few details. Sometimes I try to stick to the point but inadvertently leave out some details that can be of some use.

Cheers

You left out a lot of details.
Like the name of the Userform Label.
What value you want entered in Column AB

This script assumes your label is named label1

And you want the value 3 entered into column AB

All this would be on the active sheet.

Try this:

Code:
Private Sub CommandButton1_Click()
'Modified  7/13/2019  2:56:42 AM  EDT
Dim SearchString As String
Dim SearchRange As Range
SearchString = Label1.Caption
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "AA").End(xlUp).Row
Set SearchRange = Range("AA1:AA" & Lastrow).Find(SearchString, LookIn:=xlValues, lookat:=xlWhole)
If SearchRange Is Nothing Then MsgBox SearchString & "  Not Found": Exit Sub
SearchRange.Offset(0, 1).Value = 3
End Sub
 
Upvote 0
Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
Thank you greatly M.A.I.T. It script works as expected. My apologies for too few details. Sometimes I try to stick to the point but inadvertently leave out some details that can be of some use.

Cheers
 
Upvote 0
Using this same code, How can I adjust the code to find the record and delete that specific range? i.e. the record was found on AA19:AD19 and i want to clear this range?

Glad I was able to help you.
Come back here to Mr. Excel next time you need additional assistance.
 
Last edited:
Upvote 0
Show me the script your now using with your modifications.

And how can you find the value in:
the record was found on AA19:AD19

The script only looks in column AA

And then you said:

and
delete
that specific range? i.e. the record was found on AA19:AD19 and i want to
clear
this range?

Delete and clear are not the same.

Delete means cells are deleted.
Clear means clear the value in the range.


 
Upvote 0
I manage to figure it out.. thank you

Code:
Intersect(SearchRange.EntireRow, Range("R:U")).ClearContents
 
Upvote 0

Forum statistics

Threads
1,224,742
Messages
6,180,683
Members
452,993
Latest member
FDARYABEE

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