From worksheet launch a userform with a doubleclick and populate a textbox with the doubleclicked value

36 Views Asked by At
Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
'Updateby20171226
    If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
        Cancel = True
'            TxtBoxFUZEProjectID.Text = Cells()
            UserForm1.Show
    End If
End Sub

What do I do here?

In my UserForm1 I have a textbox named

TxtBoxFUZEProjectID

That I want to populate with the value (Text) of the cell in the worksheet I double clicked.

2

There are 2 best solutions below

0
taller On
  • In VBE, right click on UserForm1 > View Code, paste the code
Private Sub UserForm_Initialize()
    Me.TxtBoxFUZEProjectID.Value = ActiveCell.Value
End Sub
0
Darren Bartrup-Cook On

Don't use the default instance of the form.
If you change ShowModal to false a new form will open for each cell you double-click.

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)

    If Not Application.Intersect(Target, Range("B:B")) Is Nothing Then
        Cancel = True
        
        Dim MyForm As UserForm1
        Set MyForm = New UserForm1
        
        MyForm.TxtBoxFUZEProjectID = Target.Value
        MyForm.Show
        
    End If

End Sub