+ Reply to Thread
Results 1 to 3 of 3

List box macro

Hybrid View

giri_luck List box macro 10-12-2012, 10:58 PM
dwint Re: List box macro 10-12-2012, 11:14 PM
Trebor76 Re: List box macro 10-12-2012, 11:54 PM
  1. #1
    Registered User
    Join Date
    10-12-2012
    Location
    India
    MS-Off Ver
    Excel 2003
    Posts
    1

    List box macro

    hi,

    I have a macro,

    Sub Add_Drop_Down_Menu_Selection()
    With Selection.Validation
    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
    Formula1:="=$C$1:$C$39"
    .IgnoreBlank = True
    .InCellDropdown = True
    End With
    End Sub
    It lists all the contents from C1 to C39 and it runs for a selected sheet.

    I need to modify the macro so my list box is in Sheet 1 and the contents C1 to C39 is in Sheet 2.

    Thanks
    Last edited by jeffreybrown; 10-12-2012 at 11:47 PM. Reason: Added code tags for new user...Please do so next time...Thanks.

  2. #2
    Forum Contributor
    Join Date
    10-02-2012
    Location
    Bumi Nusantara
    MS-Off Ver
    Excel 2010; Excel 2016
    Posts
    136

    Re: List box macro

    change your code with this one
    Formula1:="=Sheet2!$C$1:$C$39"
    click the star if it solves your problem

  3. #3
    Forum Expert
    Join Date
    12-10-2006
    Location
    Sydney
    MS-Off Ver
    Office 365
    Posts
    3,565

    Re: List box macro

    Hi giri_luck,

    Welcome to the forum!!

    You need to create a named range for data validation to be used on data that is in a different tab from where the data validation resides. To do this, follow these four steps:

    1. Select Sheet2 and highlight the desired range (C1:C39 in this case)
    2. Press and while holding down the Ctrl tab press F3
    3. From the Name Manager dialog click the New button
    4. From the New Name dialog, enter an unique name (in the following macro I've used MyList) into the Name field, check the other details and then click OK

    Then try the following macro:

    Option Explicit
    Sub Add_Drop_Down_Menu_Selection()
    
        'Written by Trebor76
        'Visit my website www.excelguru.net.au
        
        With ActiveCell.Validation
            .Delete
            .Add xlValidateList, , , "=" & "MyList" 'This is the name I gave the named range. Change it to whatever you end up calling yours.
            .IgnoreBlank = True
            .InCellDropdown = True
        End With
    
    End Sub
    Regards,

    Robert
    ____________________________________________
    Please ensure you mark your thread as Solved once it is. Click here to see how
    If this post helps, please don't forget to say thanks by clicking the star icon in the bottom left-hand corner of my post

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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