VBA select table column based on a named range variable

Jasp30

New Member
Joined
Jul 15, 2011
Messages
8
Using VBA I am trying to save data within a table column into a saved column, the difficulty is the column to copy the data from changes each month as it is time related.

As an example the column titles are of a standard naming convention based on their type and the month e.g. "Cost Apr-19", "Cost May-10", "Cost Jun-19".....(other columns are similar for say Hours, but ignore that).

I have named cells which are populated by selecting the current month via a pull-down option, and then via a lookup table it sets the previous and next periods in named cells as well; these named ranges (cells) are titled "Period_Current_Cost", "Period_Last_Cost", Period_Next_Cost".

In an example, if the current month is May-19, the "Period_Current_Cost" would have a value of "Cost May-19" via the lookup table.

What I am trying to do is select the equivalent titled column in the table and copy & paste it into a different column within the table. A simple version of this, based on fixed named columns is below, but what (as a VBA novice) I am struggling with is replacing the static column name with the variable column name based on the named range (cell) "Period_Current_Cost" i.e. the code: ActiveSheet.Range("Table_EAC_LB[Total Cost (EAC)]").Select would actually result in selecting the current month "Cost May-19" via using the named variable.

Your help is really appreciated. Thanks in anticipation.

Application.ScreenUpdating = False

ActiveSheet.Range("Table_EAC_LB[Total Cost (EAC)]").Select
Selection.Copy
ActiveSheet.Range("Table_EAC_LB[Last Month Forecast Total Cost (EAC)]").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Application.ScreenUpdating = True
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,214,952
Messages
6,122,457
Members
449,083
Latest member
Ava19

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
Back
Top