Solved

Excel: Dynamically changing column data

Posted on 2013-01-26
4
338 Views
Last Modified: 2013-01-26
Experts:

This is a followup from a prior question:

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28009497.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
0
Comment
Question by:Rick Norris
  • 2
  • 2
4 Comments
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38822149
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

0
 

Author Comment

by:Rick Norris
ID: 38822202
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
0
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 38822226
Here is your file with my code
Copy-of-DropDownExample---3.xls
0
 

Author Closing Comment

by:Rick Norris
ID: 38822256
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now