+ Reply to Thread
Results 1 to 3 of 3

Thread: UserForm on cell selection

  1. #1
    Registered User
    Join Date
    06-15-2011
    Location
    Dorset, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    UserForm on cell selection

    I'm new to VBA so I might be missing something quite obvious.

    I want to bring up a userform (which I have renamed paymentform) whenever a cell within a particular range is selected. The range is a column in a table which varies in length so I need to use the range name rather than cell references.

    I found a similar question on the forum that gave a solution using a single cell reference rather than a range. I replaced the cell reference with my range name and nothing happens. I also tried adding Range before my range reference and did at least get an error message.

    The code looks like this:

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Target.Address(False, False) = ("sales[column14]") Then
    paymentform.Show
    End If
    
    End Sub
    Although I have created my userform and its layout I haven't yet done the code to work with the data it collects - does that make a difference?

    Any ideas?

    Cheers
    JoH
    Last edited by romperstomper; 06-20-2011 at 09:33 AM. Reason: edit tags and mark solved

  2. #2
    Registered User
    Join Date
    07-27-2010
    Location
    Sheffield, England
    MS-Off Ver
    Excel 2003
    Posts
    42

    Re: UserForm on cell selection

    Hi,

    The code below checks if the cell that has been selected (the "Target") intersects column 14 of your range "sales" (note that this might not be column 14 of the sheet as your range might not start in column A. If the selected cell is in column 14, it creates a new instance of your form and shows it.

    Private Sub Worksheet_SelectionChange(ByVal Target As Range)
        Dim frmPaymentForm As paymentform
    
        If Not Intersect(Target, Me.Range("sales").Columns(14)) Is Nothing Then
            Set frmPaymentForm = New paymentform
            frmPaymentForm.Show
        End If
    
    End Sub

    The code needs to go in the code module for the sheet that you're working on.

    Cheers,
    Dom

  3. #3
    Registered User
    Join Date
    06-15-2011
    Location
    Dorset, England
    MS-Off Ver
    Excel 2010
    Posts
    5

    Re: UserForm on cell selection

    Brilliant - it works!
    Thanks :-)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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.2.0