Results 1 to 8 of 8

VBA data validation, dependent dropdown list

Threaded View

  1. #1
    Registered User
    Join Date
    07-12-2013
    Location
    Austrlia
    MS-Off Ver
    Excel 2003
    Posts
    7

    Question VBA data validation, dependent dropdown list

    Hi everyone,

    I'm working on an excel that consists of a fill-in form within the worksheet. I understand it may be better to use a userform and activeXcontrols, but I already have 2 userform in the workbook.
    *The workbook needs to be usable by all users, therefore I can't use plug-ins.
    *I'm totally new in VBA, so please avoid "refer to this link" only. I won't be able to understand the code unless it has comments. I need to know where and which part I can/cannot change.

    I need to generate a dependent dropdown list. Which I managed to have it working, however, (as attached) I need to place the reference value in Cell M2. Is there possibly a method to not having to display a value in cell M2 and still have it working?

    Notes:
    1. information of column [F, G] and [I,J,K] is not constant, as user can add new "company", "product", "detail" to list
    2. the actual lists is separated into different worksheet (ie. sheet1 = in-sheet form, sheet2 = company list, sheet 3 = product list)
    3. reason that I'm doing this in VBA and not excel built-in functions is to avoid formula loss (overwriting the data without realizing it and then saving the workbook [which happened before])

    Possible Error:
    I realized that if the list from column I to K is not sorted according to column I, the drop down list will generate mismatch

    For example
    Col I Col J
    A apple
    A orange
    B Beef
    A Lemon

    with this list above, the dependent drop down list for A will be (apple, orange, BEEF). It can count there are 3 "A" but the results are shifted.

    I appreciate for your help!


    Private Sub Worksheet_Change(ByVal Target As Range)
    
        Dim selected_company As String
        
        With Worksheet("sheet1")
            If .Range("a2") = Empty Then
                .Range("b2,c2,m2") = Empty
                Exit Sub
            Else
                selected_company = Application.WorksheetFunction.VLookup(.Range("A2"), .Range("F:G"), 2, False)
                    
                With .Range("B2").Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:= _
                    "=OFFSET(OFFSET(I:I,0,1,1,1),MATCH(M2,I:I,0)-1,0,COUNTIF(I:I,M2))"
                    'perheps i can replace M2 with selected_company, but as I have tried it didn't work
                End With
            End If
        End With
    
    End Sub
    Attached Files Attached Files
    Last edited by revzephyr; 03-11-2014 at 09:55 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Dependent dropdown validation - dependent data is string
    By jnewby in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-12-2014, 07:50 PM
  2. Data Validation List - Dependent on Adjacent Cell - Value from Unsorted List
    By justforthis1 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 03-26-2013, 12:24 PM
  3. Replies: 2
    Last Post: 07-17-2012, 01:18 PM
  4. 4 way dependent dropdown/data validation
    By Cidona in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-19-2012, 06:58 AM
  5. Excel 2007 : Dependent Dropdown (Data Validation)
    By mtpr220 in forum Excel General
    Replies: 16
    Last Post: 08-10-2011, 12:58 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