Vlookup in VBA

zdodson

Board Regular
Joined
Feb 29, 2012
Messages
124
I have two textboxes, and a range:

Textbox Names:
txtArea
txtPerimeter

Range: (A2:B100)

I want txtArea to populate txtPerimter based on the value that I put in txtArea using vlookup.

Pretty basic, just having a difficult time with it, and I can't find anything on the internet that speaks to the specificity of this request.


Thanks,
Zack
 

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)
See if this macro works for you...
Code:
Sub UpdatePerimeterFromArea()
  On Error Resume Next
  ActiveSheet.txtPerimeter.Value = Columns("A").Find(ActiveSheet.txtArea.Value, LookAt:=xlWhole, _
                                                     MatchCase:=False).Offset(, 1).Value
  On Error GoTo 0
End Sub
 
Upvote 0
Where do you put this code? Do you put it behind the userform or the textbox?
The code should go in the UserForm's module, but how you call it depends on how your UserForm is structured and how the user is supposed to interact with it. If you have a "Done" or "Next" type button, I would call the macro from its Click event. If you want the code to execute when the user has left the TextBox, then you can call the macro from the TextBox's LostFocus event. There are probably a few other possible scenarios as well, so again, the answer is "it depends".
 
Upvote 0

Forum statistics

Threads
1,203,537
Messages
6,055,976
Members
444,839
Latest member
laurajames

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