+ Reply to Thread
Results 1 to 3 of 3

want to get selected region address in textbox

Hybrid View

vini1508 want to get selected region... 02-17-2016, 06:51 AM
LJMetzger Re: want to get selected... 02-21-2016, 04:17 PM
vini1508 Re: want to get selected... 03-02-2016, 01:33 AM
  1. #1
    Registered User
    Join Date
    02-08-2016
    Location
    Maharashtra
    MS-Off Ver
    Office 2010
    Posts
    11

    Question want to get selected region address in textbox

    i have a userform.. when a form loads i want to select the range from active sheet and after i select a range i want to display the selected cell address in textbox.. i want to do this automatically without using inputbox or clicking any button... i want to select the range and its address should be displayed in textbox... plss help

    also it is an addin which i'm creating so i guess i wont be able to use Worksheet_SelectionChange Event
    Last edited by vini1508; 02-17-2016 at 06:53 AM.

  2. #2
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: want to get selected region address in textbox

    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

  3. #3
    Registered User
    Join Date
    02-08-2016
    Location
    Maharashtra
    MS-Off Ver
    Office 2010
    Posts
    11

    Re: want to get selected region address in textbox

    Thanks LJMetzger

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 06-01-2015, 06:23 PM
  2. [SOLVED] Textbox and Option Buttons - If Textbox has a Value then an Option Button must be selected
    By MeerkatMatt in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-08-2014, 07:45 AM
  3. How do I shade a region between two selected points on the x axis?
    By cmc14 in forum Excel Charting & Pivots
    Replies: 3
    Last Post: 05-09-2014, 01:40 PM
  4. Replies: 4
    Last Post: 05-17-2012, 06:30 PM
  5. Replies: 1
    Last Post: 03-08-2012, 01:57 PM
  6. Replies: 1
    Last Post: 10-04-2007, 12:04 PM
  7. Highlight all Text in a Textbox when the textbox is selected
    By RPIJG in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-28-2005, 03:28 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1