Variable Column Selections Macro

Craig13_13

New Member
Joined
Apr 9, 2009
Messages
21
Hello all

I'm trying to write a Macro for the following:
I have a list of suppliers in column A and each month a score is generated for that supplier and the data put in columns, i.e. B has january score, C has february score etc.

I want the macro to arrange the suppliers in order of the last entered score, for example if there is data up until the march column i want it to arrange them by that score.

So far I can get it to find the last column with data in, I can get it to highlight that one but the bit I'm struggling with is "dynamic selection" if you like, I can get it to highlight the final column, but not the final column plus all the previous ones.

All suppliers are given a score at once so there will never be a blank cell in a column as such - it's all or nothing!

Any help would be much appreciated.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Try generating your macro via the Macro Recorder - via Cells/Sort.

Once you've done that, you just need to "tweak" it to identify the last column - which you say you know how to identify.
 
Upvote 0
Thanks for the suggestion, unfortunately when you use the Macro recorder to select in this manner it sets a defined range (say "A6:D100"), and I can't figure out how to get that second number to be the end column

Highlighting end column of data code is as follows:

Range("a6").Select
Selection.End(xlToRight).Select
ActiveCell.EntireColumn.Select
 
Upvote 0
You should be able to replace you code with

Code:
Range("a6").End(xlToRight).EntireColumn.Select

but you don't need to 'select' a range in order to do things with it.

you could define the range of all the data in the last column as

Code:
lastCol = cells(6,columns.count).end(xltoleft)
set lastrange = range(cells(6,lastcol),cells(rows.count,lastcol).end(xlup))
 
Upvote 0
Thanks for the suggestion, unfortunately when you use the Macro recorder to select in this manner it sets a defined range (say "A6:D100"), and I can't figure out how to get that second number to be the end column

Highlighting end column of data code is as follows:

Range("a6").Select
Selection.End(xlToRight).Select
ActiveCell.EntireColumn.Select

I really have no idea what you want to do, but merely to establish the column number from the code you have posted :-

Dim c%
Range("a6").Select
Selection.End(xlToRight).Select
c=Selection.Column
 
Last edited:
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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