userform and events
Hi
Worksheet_SelectionChange is an event code so it has to be in the code sheet
for desired sheet.
To make it work you also have change the ShowModal property of the userform
to False.
Hopes this helps
....
Per
"Lena" skrev i meddelelsen
...
Hello. I have a user form with a text box that shows currently selected
cell.
If a user clicks on another cell I want the text box to be updated with
that
cell address. I tried using Private Sub Worksheet_SelectionChange(ByVal
Target As Range). But I don't know where to put it because nothing happens
when the cell is clicked. Do I need to create a class? Here's how my subs
look:
Option Explicit
Dim clAdr As String
Private Sub UserForm_Initialize()
clAdr = ActiveCell.Address(rowabsolute:=False,
columnabsolute:=False)
UserForm1.TextBox1.Text = clAdr
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Application.EnableEvents = False
If Target.Address < UserForm1.TextBox1.Text Then
UserForm1.TextBox1.Text = Target.Address
End If
Application.EnableEvents = True
End Sub
|