Swapping Named Cell Ranges Using Drop Down List

Alex21345

New Member
Joined
Aug 26, 2019
Messages
4
I have searched all through google and cannot seem to find vba code to get me to what Im trying to accomplish.

I have named the following groups of columns by going to Fomulas, then Define Name.

Columns V:AB are named "Position_1"
Columns AC:AI are named as "Position_2"
Columns AJ:AP are named as "Position_3"
Columns AQ:AW are named as "Position_4"
and so on...

My idea behind naming the groups of cells was to make it easier to code once im up to 10+ "Positions"

Each "Position" grouping is exactly the same in size, font, color etc. The only thing that will be different is the data that will be placed into the columns. Each "Position" will be assigned to a Subcontractor. ("Position_1" will contain Subcontractor 1's data. "Position_2" will contain Subcontractor 2's data, and so on.

My goal is to create a drop down selection menu containing Subcontractors 1, Subcontractor 2, Subcontractor 3 and so on. When one of these Subcontractors are selected, I would like the the entire group of columns for that Subcontractor to be swapped with "Position_1", where Subcontractor 1 is currently sitting.

Example: if Subcontractor 2 is selected in the drop down list, then it will swap positions with Subcontractor 1 ("Position_2" will swap with "Position_1"). If subcontractor 4 is selected from the drop down list, it would then be swapped with what ever Subcontractor is sitting in "Position_1"). Every time a new Subcontractor is selected, I do not want to loose the Subcontractors data in the "Position_1" columns, I simply just need to replace it with the selection, and move it to the spot that the previous data was in.

If using named cells like I currently have set up (Position_1, Position_2, etc.) is much harder to code, I'd be open to just using cell ranges such as V:AB, AC:AI, etc. Both will achieve the same thing

Any help on this would be greatly appreciated. I hope my intent makes sense. Thank you!
 

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
16,272
You mentioned you want to do things this way to make further coding easier.

I believe in doing things this way could be difficult.

Please explain your ultimate Goal and maybe we could provide a better way to do things.

Moving entire columns of data around can be done but there has to be a way to not copy over previous data.
 

Alex21345

New Member
Joined
Aug 26, 2019
Messages
4
Sub MOVE_SUBCONTRACTOR2()


Dim temp As Double

temp = Range.Columns("V:AB").Value

Range.Columns("V:AB").Value = Range.Columns("AC:AI").Value

Range.Columns("AC:AI").Value = temp

End Sub
 

Alex21345

New Member
Joined
Aug 26, 2019
Messages
4
Oops didnt mean to send out that previous post, but anyways, above is the code I tried. I was planning on making a module like that for each Subcontractor. The ultimate goal is just to move a subcontractor into the "Position_1" column area (AKA Column V:AB) by selecting the Subcontractor name from a drop down selection list. If I can get the code above to work I should be able to figure out the rest I think.

The goal of the code I posted above was to swap columns AC:AI with columns V:AB.

Thanks for the help
 

Akuini

Well-known Member
Joined
Feb 1, 2016
Messages
2,356
Office Version
2013
Platform
Windows
Untested but maybe this:
Say cell A1 is where the data validation is located, after selecting an item in the data validation run the code.
If you want it to be run automatically after selecting an item in the data validation then you need to use Sub Worksheet_Change (but with different code).


Code:
Sub MOVE_SUBCONTRACTOR3()
Dim va, tx As String
tx = Range("A1").Value
        va = Range("Position_1").Value
        Range("Position_1").Value = Range(tx).Value
        Range(tx).Value = va

End Sub
 

Forum statistics

Threads
1,081,834
Messages
5,361,594
Members
400,639
Latest member
fleyd

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top