Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Excel: Dynamically changing column data

Posted on 2013-01-26
Medium Priority
398 Views
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
Question by:Rick Norris
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 2
• 2

LVL 43

Expert Comment

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 = 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
``````
0

Author Comment

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

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

Author Closing Comment

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

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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.
How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns overâ€¦
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
###### Suggested Courses
Course of the Month4 days, 23 hours left to enroll