Lookup a value on a UserForm

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,341
Office Version
  1. 365
Platform
  1. Windows
I have a Userform (Userform1) where I have two Text Boxes (Textbox1 and Textbox2).

When the user right clicks on a cell in Sheet1 I want to open Userform1 and populate Textbox1 with the data from the cell to the right of where they right clicked Target -1
Then I want to perform a lookup of that data find its match in column C of sheet1 and get the associated data from column D and then place that result in Textbox2



In addition to that, when the user click commandbutton1 on the userform, I want to close userform1 but I want to copy the found data in Textbox2 so that they can paste it in the Target if they choose to once they are back on sheet1 (But I don't want to automatically past it. I want them to have to manually paste it)

Is this even possible?
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I give it a try

here is the code for Userform

Code:
Private Sub CommandButton1_Click()
Unload Me

On Error Resume Next
Set myRange = Application.InputBox(Prompt:="Please click on the cell you want to paste you data", _
Title:="Select Cell", Type:=8)
r = myRange.Row
c = myRange.Column
If myRange Is Nothing Then Exit Sub
Cells(r, c) = TextBox2

End Sub

Private Sub UserForm_Initialize()
Data = ActiveCell.Offset(0, 1).Value
If Data = "" Then Exit Sub
TextBox1 = Data
TextBox2 = Cells(WorksheetFunction.Match(Data, Range("C:C")), "D")

End Sub


here is the code for the sheet you plan on using for the right-click

Code:
Private Sub Worksheet_BeforeRightClick(ByVal Target As Range, Cancel As Boolean)
    
    Dim vTemp As Variant
    
    If Target.Count > 1 Then Exit Sub
    
    If Not Intersect(Target, Cells) Is Nothing Then
    
        Call Open_userForm
        Cancel = True
    End If
    
End Sub

let me know how it works.

Ross
 
Upvote 0

Forum statistics

Threads
1,214,948
Messages
6,122,420
Members
449,083
Latest member
Ava19

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