Link to home
Start Free TrialLog in
Avatar of Rick Norris
Rick Norris

asked on

Excel: Dynamically changing column data

Experts:

This is a followup from a prior question:

https://www.experts-exchange.com/questions/28009497/Excel-Dynamically-changing-drop-down-items-AND-data-for-the-items.html

This is the second follow-up ...  the link to the original question is "inside" the above link.

The solution to the prior question completely solved my problem as asked; however it had constraints that will not allow it to work with my "real world" data; hence, this followup.

I am attaching an excel spreadsheet that contains a representative sample of the data that i will be importing into my software.  This example DOES NOT include the solution from the question referenced above.

ssaqibh:  I hope you stick around and solve this conundrum as you have so graciously done for the last two questions.

Sincerely,
Rick Norris
DropDownExample---3.xls
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

This will work for DV cells in the range D2:K2
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim cel As Range
    Dim scel As Range
    Dim dv
    Dim dvn() As String
    Dim nf As Boolean
    Dim tmp As Variant
    If Target.Count = 1 And Not Intersect(Target, Range("G2:K2")) Is Nothing Then
        For Each cel In Range("G2:K2")
            If cel.Address <> Target.Address Then
                If cel = Target Then
                    dvn = Split(Replace(ThisWorkbook.Names(Replace(cel.Validation.Formula1, "=", "")).RefersTo, "=", ""), "!")
                    For Each dv In Sheets(dvn(0)).Range(dvn(1))
                        nf = False
                        For Each scel In Range("G2:K2")
                            If scel = dv Then nf = True: Exit For
                        Next scel
                        If Not nf Then
                            cel = dv
                            tmp = Target.Offset(1).Resize(Target.EntireRow.Cells(1).End(xlDown).Row - Target.Row).Value
                            Target.Offset(1).Resize(Target.EntireRow.Cells(1).End(xlDown).Row - Target.Row).Value = cel.Offset(1).Resize(cel.EntireRow.Cells(1).End(xlDown).Row - cel.Row).Value
                            cel.Offset(1).Resize(cel.EntireRow.Cells(1).End(xlDown).Row - cel.Row).Value = tmp
                            Exit Sub
                        End If
                    Next dv
                End If
            End If
        Next cel
    End If
End Sub

Open in new window

Avatar of Rick Norris
Rick Norris

ASKER

ssaqibh:

You first two solutions worked perfectly for the question asked....  I tried above....  now the drop downs are back as the original question posed....  I'm sure there is just some little thing in the code that is causing the problem....  Dropdown items do not "swap", as in your solution to the first question....  and the swapping of the data as you solved in the first follow-up question is not working now.....  even if I revert to "uniform" data as show in the second follow-up question....   If you could be so kind as to look over the code again it would be most appreciated....  At current time it is beyond my ability; however, I plan on spending some time with the code to truly understand what you have written.

Thanks again,
Rick Norris
ASKER CERTIFIED SOLUTION
Avatar of Saqib Husain
Saqib Husain
Flag of Pakistan image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ssaqibh:

Once again....  you solution was flawless!!

I'm sure I did something "stupid" when I copied above code into my spreadsheet.

More thanks and "kudos" to you!!

Rick Norris