UserForm Reads contents from the selected cell

No-data

New Member
Joined
Jan 12, 2012
Messages
1
Hi guys!
Here is my problem: I want to show selected cell's content into
an userForm's TextBox. I've tried to use the Worksheet_SelectionChange event without succes. Here is my code:

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Static Direccion As String
        Direccion = Target.Address(False, False)
        MsgBox Direccion
        Cells(6, "Q").Value = Target.Value
        UserForm2.Show
    
End Sub

My idea is to get the addres of the current selection with the Worksheet_SelectionChange event, save it to a variable called "Direccion" and when I initialize my UserForm read the value from the "Direccion" Variable into the textBox. However I the values is not showed =(.

and

Code:
Private Sub UserForm_Initialize()
 
 
 txtPerfil.Value = Direccion
 'Target.Address(False, False)

End Sub
Hope someone could help me!
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
The variable "Direccion" is only visible within the SelectionChange event. Modules outside that event cannot use it or reference it. In order to do so, create a Standard Module and in it declare a Public variable. You can then reference that variable in any module or sub within the vba project.
Code:
Public Direccion as String
Also remember to remove the Static variable you declared in the SelectionChange event!
 
Upvote 0

Forum statistics

Threads
1,214,430
Messages
6,119,453
Members
448,898
Latest member
drewmorgan128

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