Use lookup to enter value in the adjacent cell

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
949
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.
 

Some videos you may like

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
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
 

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
949
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
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
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
 

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
949

ADVERTISEMENT

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:

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,252
Office Version
  1. 2013
Platform
  1. Windows
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.


 

Av8tordude

Well-known Member
Joined
Oct 13, 2007
Messages
949
I manage to figure it out.. thank you

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

Watch MrExcel Video

Forum statistics

Threads
1,122,737
Messages
5,597,826
Members
414,180
Latest member
Sir Khaya

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
Top