Solved

Excel:  Dynamically changing drop down items AND data for the items.

Posted on 2013-01-25
3
412 Views
Last Modified: 2013-01-26
Experts:

I asked a previous question.  Was answered completely...  this is a followup.  You may want to refer to below, and the solution.

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28008108.html

Additional question:

I would now like to have the data in columns g thru k also move when the dropdown item list changes.

Please see attached Excel file for example of what I need.  Please see code behind the "data" tab for what is working currently...  Code was very kindly provided by ssaqibh!

thanks in advance.

Rick D Norris
DropDownExample---New.xls
0
Comment
Question by:Rick Norris
  • 2
3 Comments
 
LVL 43

Accepted Solution

by:
Saqib Husain, Syed earned 500 total points
ID: 38821600
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("G1:K1")) Is Nothing Then
        For Each cel In Range("G1:K1")
            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("G1:K1")
                            If scel = dv Then nf = True: Exit For
                        Next scel
                        If Not nf Then
                            cel = dv
                            tmp = Target.Offset(1).Resize(Target.End(xlDown).Row - Target.Row).Value
                            Target.Offset(1).Resize(Target.End(xlDown).Row - Target.Row).Value = cel.Offset(1).Resize(cel.End(xlDown).Row - cel.Row).Value
                            cel.Offset(1).Resize(cel.End(xlDown).Row - cel.Row).Value = tmp
                            Exit Sub
                        End If
                    Next dv
                End If
            End If
        Next cel
    End If
End Sub
0
 
LVL 43

Expert Comment

by:Saqib Husain, Syed
ID: 38821604
This will work if there are no gaps in the data

and

the heights of all columns are the same
0
 

Author Closing Comment

by:Rick Norris
ID: 38822133
ssaqibh:

‘Dwarfs standing on the shoulders of giants see farther ahead than the giants.’ Pascal

I am a dwarf, but with your help, my software project has been enhanced well beyond what I was capable

My example did not take into account the very HIGH probability of "gaps".... concerning heights......  Not sure if I understand???

Because the constraint you mentioned in your solution would not work in what I want as an end product, I am posting another follow-up question.  I have included an example that is a sampling of data that is representative of what I will be importing into my software.

http://www.experts-exchange.com/Software/Office_Productivity/Office_Suites/MS_Office/Excel/Q_28009826.html

You continued participation is very much appreciated.

Thanks again,
Rick Norris
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 how to use longer labels with horizontal bar charts instead of the vertical column chart.

862 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

23 Experts available now in Live!

Get 1:1 Help Now