+ Reply to Thread
Results 1 to 18 of 18

conditional drop down list

Hybrid View

  1. #1
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    conditional drop down list

    my problem is on sheet 2 of the sample 1 file:

    if you write a value in J8 the column H3:H19 changes according to the value range in A3:A85 or range D3:D43.
    and in k8 is the drop down list for range H3:H19

    i need to do this action in VBA because I'll have to do this for multiple cells for example in J8, J9, J10 and so on with their respective drop down list.

    thank you for your help.
    Attached Files Attached Files

  2. #2
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    Try:
    Sub Test2()
        Dim rng1 As Range
        Dim rng2 As Range
        For Each rng1 In Range("A1:A7")
            If rng1 = Range("E9") Then
                With Range("F9").Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=$B$1:$B$7"
                End With
                Exit For
            End If
        Next rng1
        For Each rng2 In Range("A9:A15")
            If rng2 = Range("E9") Then
                With Range("F9").Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=$B$9:$B$15"
                End With
                Exit For
            End If
        Next rng2
    End Sub
    You can say "THANK YOU" for help received by clicking the Star symbol at the bottom left of the helper's post.
    Practice makes perfect. I'm very far from perfect so I'm still practising.

  3. #3
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: conditional drop down list

    can you show me how to use it in the sheet i don't know how to add a vba in a dropdown list

  4. #4
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    Do the following: Hold down the ALT key and press the F11 key. This will open the Visual Basic Editor. In the menu at the top click 'Insert' and then click 'Module'. Copy and paste the macro into the empty code window that opens up. Press the F5 key to run the macro. Close the code module window to return to your sheet. There are other quicker ways to run the macro such as assigning it to a button that you would click on your sheet or assigning it to a short cut key.

  5. #5
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: conditional drop down list

    i followed to the letter what you said and still not working

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    Try the attached file. Enter your value in cell E9 and then click the 'Add Validation' button. If you want to add the validation list automatically upon entering the value in E9 without having to click the button, please let me know.
    Attached Files Attached Files

  7. #7
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: conditional drop down list

    thanks it works but yes it would be nice without pressing the button

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    Try this attachment.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: conditional drop down list

    if you show me an example of how to write the macro i will write the locations for the rest but just for info the targets are
    A7:A20 , K7:K20 , V7:V20
    A38:A51 , K38:K51 , V38:V51

    for a total of 84 targets

  10. #10
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    Replace the macro in the worksheet code module with this one:
    Option Compare Text
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Intersect(Target, Range("A7:A20, A38:A51, K7:K20, K38:K51, V7:V20, V38:V51")) Is Nothing Then Exit Sub
        Dim rng1 As Range
        Dim rng2 As Range
        For Each rng1 In Range("A1:A7")
            If rng1 = Target Then
                With Cells(Target.Row, Target.Offset(0, 1).Column).Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=$B$1:$B$7"
                End With
                Exit For
            End If
        Next rng1
        For Each rng2 In Range("A9:A15")
            If rng2 = Target Then
                With Cells(Target.Row, Target.Offset(0, 1).Column).Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                        xlBetween, Formula1:="=$B$9:$B$15"
                End With
                Exit For
            End If
        Next rng2
    End Sub

  11. #11
    Registered User
    Join Date
    01-18-2014
    Location
    canada
    MS-Off Ver
    Excel 2003
    Posts
    39

    Re: conditional drop down list

    thx you're awsome

  12. #12
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,876

    Re: conditional drop down list

    My pleasure. I'm glad it worked out.

+ 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. conditional drop down list
    By K-Ching in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-25-2014, 01:09 AM
  2. conditional drop down list
    By ADSK in forum Excel General
    Replies: 2
    Last Post: 11-25-2007, 04:27 PM
  3. conditional drop down list
    By scott in forum Excel General
    Replies: 3
    Last Post: 06-03-2006, 02:10 AM
  4. [SOLVED] Need a conditional drop-down list (list contents)
    By S&F Tie Guy in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-31-2006, 10:25 AM
  5. Conditional Drop Down List
    By Bogo in forum Excel General
    Replies: 2
    Last Post: 02-16-2006, 05:15 PM

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