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!
 

Some videos you may like

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
17,265
Office Version
  1. 2013
Platform
  1. Windows
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,937
Office Version
  1. 365
Platform
  1. 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
 

Watch MrExcel Video

Forum statistics

Threads
1,123,391
Messages
5,601,396
Members
414,448
Latest member
Jessica 22664

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top