+ Reply to Thread
Results 1 to 6 of 6

Excel 2003 - Creating Named ranges for a validation list box using a case statement

Hybrid View

  1. #1
    Registered User
    Join Date
    03-08-2013
    Location
    Derbyshire
    MS-Off Ver
    Excel 2003
    Posts
    46

    Excel 2003 - Creating Named ranges for a validation list box using a case statement

    In the NewPosts worksheet I have the following information
    AACleaner
    AACleaner2
    AACleaner3
    BBTeacher1
    BBTeacher2
    BBTeacher3
    CCAssistant1
    CCAssistant2
    CCAssistant3

    And I have 3 categories (Named Ranges) JobFamilyAA, JobFamilyBB and JobFamilyCC

    To do the named range I have highlighted a section. Entered the Name range at the top and then pressed enter to commit this range.

    In sheet 1 I have the following.

    A B C D
    Name Post Job_Family_desc NewPost
    Sam Smith Cleaner Relief AA
    Sara Smith Teaching 3 BB
    Jim Brown Care Assistant 1 CC

    And I need to create a drop down list for Column D based on the ranges in NewPosts.


    So Go to D2. If C2 Job_Family_Desc = “AA” Then use Range JobFamilyAA as validation list
    If C2 Job_Family_Desc = “BB” then use Range JobFamilyBB as validation list

    If C2 Job_Family_Desc = “CC’ Then use Range JobFamilyCC as validation list

    If C2 Job_Family_Desc = “” Then End (Come out or this condition and got to the next bit of the macro)

    Then Go to Next one down D3 and repeat until C2 is Empty

    Im currently trying lots of things to get this working but if anyone had any tips that would be great

    Debbie

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Excel 2003 - Creating Named ranges for a validation list box using a case statement

    Hi,,

    It might need a macro but upload your workbook and note in column D which list you expect to see.
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    03-08-2013
    Location
    Derbyshire
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Excel 2003 - Creating Named ranges for a validation list box using a case statement

    Ill definitely be using a macro.

    I recorder one that creates a validation for every row so you do one, Check the validation, Set the List box accordingly and move onto the next row. Repeat until you are finished

    WorksheetTo_Test_Validation_From_Multiple_Ranges.xls

  4. #4
    Forum Expert
    Join Date
    07-20-2011
    Location
    Mysore, India.
    MS-Off Ver
    Excel 2019
    Posts
    8,710

    Re: Excel 2003 - Creating Named ranges for a validation list box using a case statement

    Pl See the attached file.

  5. #5
    Registered User
    Join Date
    03-08-2013
    Location
    Derbyshire
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Excel 2003 - Creating Named ranges for a validation list box using a case statement

    Hiya,

    Im not sure what you have done but it looks to have worked.

    Could you possibly pop in a description of what to do with the info supplied?

    Debbie

  6. #6
    Registered User
    Join Date
    03-08-2013
    Location
    Derbyshire
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Excel 2003 - Creating Named ranges for a validation list box using a case statement

    I think Ive cracked it!!!

    Sub Test_Validation_List_With_If_Statement_3()
    '
    ' Macro recorded 01/03/2013 by A2701687
    ' This Macro is Used within the XLS on its own when the school is happy that they have filled the NewPosts column in
    
    'Go back to sheet 1 from the instructions sheet
        Sheets(1).Select 'This selects sheet 1 no matter what it is called
         Range("D2").Select 'This takes you to the NewPost Column that is needed to be sorted out.
             
    'Brand new section. we dont want them to protect if they havent done everything neccessary
    
        Dim i As Long, lrow As Long ', Lastrow As Long
    
    With Worksheets(1)
        lrow = .Range("C" & .Rows.Count).End(xlUp).Row
        
        'For To Clause. When the counter i is at 2 (The first actual value. Remember the first few rows are taken up with the button
        'to the number of the row we are on.
        'The final value of the of the i counter in the above loop will be after 1row.
        ' i starts on row 2 and the 1row
    
        
        For i = 2 To lrow
        'If Job_Family_Desc = AA use the AA range as a validation list
                If .Range("C" & i).Value = "AA" Then
    
                        With Selection.Validation
                            .Delete
                            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                            xlBetween, Formula1:="=JobFamilyAA"
                            .IgnoreBlank = True
                            .InCellDropdown = True
                            .InputTitle = ""
                            .ErrorTitle = ""
                            .InputMessage = ""
                            .ErrorMessage = ""
                            .ShowInput = True
                            .ShowError = True
                        End With
                        
                        'And when you have done it you want to go down to the next row
                        'Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
                        Selection.Offset(1, 0).Select
    
               'Exit Sub If you use that at this point you go right to the top of the sub again
    
        'If Job_Family_Desc = BB use the BB range as a validation list
                ElseIf .Range("C" & i).Value = "BB" Then
    
                        With Selection.Validation
                            .Delete
                            .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                            xlBetween, Formula1:="=JobFamilyBB"
                            .IgnoreBlank = True
                            .InCellDropdown = True
                            .InputTitle = ""
                            .ErrorTitle = ""
                            .InputMessage = ""
                            .ErrorMessage = ""
                            .ShowInput = True
                            .ShowError = True
                        End With
                        
                        'And when you have done it you want to go down to the next row
                       
                        'Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
                        Selection.Offset(1, 0).Select
               'Exit Sub If you use that at this point you go right to the top of the sub again
             
        'If Job_Family_Desc = CC use the CC range as a validation list
                ElseIf .Range("C" & i).Value = "CC" Then
    
                    With Selection.Validation
                        .Delete
                        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=JobFamilyCC"
                        .IgnoreBlank = True
                        .InCellDropdown = True
                        .InputTitle = ""
                        .ErrorTitle = ""
                        .InputMessage = ""
                        .ErrorMessage = ""
                        .ShowInput = True
                        .ShowError = True
                    End With
                    
                        'And when you have done it you want to go down to the next row
    
                        'Lastrow = Cells(Rows.Count, 1).End(xlUp).Row
                        Selection.Offset(1, 0).Select
                        
               'Exit Sub If you use that at this point you go right to the top of the sub again
    
        'If Job_Family_Description Is empty then the file is done so we can come out of this IF THEN ELSE Condition
                ElseIf .Range("C" & i).Value = "" Then
                
                
                Exit Sub
            End If
        Next i
    End With
    
    End Sub
    Last edited by DebbieEdwards; 04-17-2013 at 10:43 AM. Reason: I hadnt added the Code sections

+ 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