Hi vini1508,
Try the following code which is included in the attached file. Remove the code from the 'Sheet1' module if you don't want to be able to change the range after the UserForm is displayed. To be able to change the range after the UserForm is displayed you need a 'Modeless' UserForm which DOES NOT lock out Excel.
In the Sheet1 code module:
Option Explicit
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
'Change the Address in UserForm1, TextBox1
If bGblHaveUserForm1 = True Then
UserForm1.TextBox1.Value = Target.Address(False, False) '(False, False) disables display of '$' signs in the Address
End If
End Sub
In the UserForm1 Code Module:
Option Explicit
Private Sub UserForm_Terminate()
bGblHaveUserForm1 = False
End Sub
In Ordinary code module ModUserForm1:
Option Explicit
Public bGblHaveUserForm1 As Boolean
Public Sub DisplayUserform1()
'''''''''''''''''''''''''''''''''''''''''''''''''''''
' IMPORTANT - READ BELOW ABOUT INITIALIZATION
'
'In the .show command
'"True" or BLANK or vbModal locks out everything but the form.
'"False" or vbModeless allows other actions to be performed.
'''''''''''''''''''''''''''''''''''''''''''''''''''''
UserForm1.TextBox1.Value = Selection.Address(False, False) '(False, False) disables display of '$' signs in the Address
bGblHaveUserForm1 = True
UserForm1.Show vbModeless
End Sub
Lewis
Bookmarks