+ Reply to Thread
Results 1 to 5 of 5

Thread: add new value to named range

  1. #1
    Registered User
    Join Date
    04-03-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    41

    add new value to named range

    Hi All,
    I have a named range that I want to be able to grow with newly added items. For example: we have a customer list in an in-cell drop down that is referenced in a named range. I would like to be able to select an existing customer or add a new customer, if the customer doesn't exist. Is there a way to do this in VBA? Thanks in advance.
    Last edited by wpryan; 05-26-2010 at 11:06 AM. Reason: Solved

  2. #2
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: add new value to named range

    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  3. #3
    Registered User
    Join Date
    04-03-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: add new value to named range

    Thanks for your reply. I tried this, and it works only if the named range is in the same worksheet as the drop-down box. I need the range to be in another worksheet, therefore I suppose I need to declare the range as being in the other worksheet. I'm afraid I don't know how to do that. ...care to help?

  4. #4
    Forum Guru NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    32,636

    Re: add new value to named range

    Try:

    Private Sub Worksheet_Change(ByVal Target As Range)
    
    
    
    Dim lReply As Long
    
    
    
        If Target.Cells.Count > 1 Then Exit Sub
    
            If Target.Address = "$A$1" Then
    
                If IsEmpty(Target) Then Exit Sub
    
                    If WorksheetFunction.CountIf(Sheets("Sheet2").Range("MyNames"), Target) = 0 Then
    
                        lReply = MsgBox("Add " & Target & " to list", vbYesNo + vbQuestion)
    
                            If lReply = vbYes Then
    
                                Sheets("Sheet2").Range("MyNames").Cells(Sheets("Sheet2").Range("MyNames").Rows.Count + 1, 1) = Target
    
                            End If
    
                    End If
    
            End If
    
    End Sub
    Replace the sheetname, Sheet2 with the sheet that has the list.

    Also, replace $A$1 in Target.Address = "$A$1" with the cell containing the dropdown list.
    Microsoft MVP - Excel

    Where there is a will there are many ways. Pick One!


    Please read the Forum Rules

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

    Preferred Charities: Lupus Canada and Sick Kids Foundation.
    Feel Free to Donate if you want to, for the assistance you received today.

  5. #5
    Registered User
    Join Date
    04-03-2010
    Location
    Orlando, FL
    MS-Off Ver
    Excel 2007
    Posts
    41

    Re: add new value to named range

    That's fantastic, 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