defining dynamic column range where column order changes

rb3883

New Member
Joined
Nov 23, 2008
Messages
24
I receive a daily file of data and I need to highlight one of the columns and then perform operations on it. In the past the data would arrive in exactly the same format and the data was always in column G so I could use the following code:

Range(Range("G2"), Range("G" & Rows.Count).End(xlUp))

Now the order of columns varies and some data is completely omitted.

I can identify the column by it's title which is fine but then I have been unable to then select the column of data below it. I tried to define variables for the addresses of the top cell (which is the column title cell) and then do the same for the last cell of the data but i'm struggling have been racking my brains for a while now, any ideas pls?
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
I've used this code before. Go to your header, then this will select everything below it (shift-ctrl-down)

Range(ActiveCell, ActiveCell.End(xlDown)).Select
 
Upvote 0
Thanks for that but unfortunately that doesn't work if there are spaces in the data. As it happens I think I can create a variable that extracts the letter of the column of the active cell by using the following code:

dim ColumnLetter as variant

Column Letter = Left(activecell.address, 2)

Cheers
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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