Make macro: "go to end of data"

livemusic

New Member
Joined
Jul 3, 2011
Messages
17
I have data in columns and need a macro to do certain things to the data. Is there a way to make a macro that... here is what I manually do... I put my cursor in the cell where the first of the data begins. I then pull my mouse down to highlight that column's data all the way to the last entry (blank cell below it), then I drag over to the right x-number of columns (which is always the same for each table of data), such that I am selecting the entire table of data. Then I sort on Column A (which is date) and then choose 'oldest to newest.' Then I do some other stuff, but I'll end this post with this 'highlighting/sorting' question.

My spreadsheet consists of numerous tables of data like this and I am always adding more sets of data. Thus, need a macro. Can this be done with a macro? The number of rows varies with each table set (how deep I drag my mouse), that is why I question if it can be done.
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Code:
[COLOR="Blue"]Sub[/COLOR] SortRange()
    Range(ActiveCell, ActiveCell.End(xlDown)).Sort Key1:=ActiveCell, Order1:=xlDescending
[COLOR="Blue"]End[/COLOR] [COLOR="Blue"]Sub[/COLOR]
 
Upvote 0
Have you tried selecting from the menu: Developer - then Record Macro - and then doing what you need to have done manually? This will write the macro for you.
 
Upvote 0
Have you tried selecting from the menu: Developer - then Record Macro - and then doing what you need to have done manually? This will write the macro for you.

I don't see how it could work manually. That is the question. If it does, that is far simpler for me, as I am not a programmer. I mean, if I record the macro on a given set of data, the next set of data may be a different number of rows. So, how would it know, without using programming language to 'go down to the bottom of the data to where the next cell is blank.'

As for Sektor's code, thank you... is that Visual Basic? I assume it is and I figured out how to paste your code into the Visual Basic Editor. Then I selected the macro and pressed Run. But it does nothing. Am I doing something wrong?
 
Upvote 0
You need to select first cell. Then macro will locate last cell and sort this range.
 
Upvote 0
I just recorded a macro manually, named it. Then selected it and clicked Run. It worked. But if I select your macro and run it, nothing happens. Any idea what setting I may have set wrong?

Oh... I see that it is working. You have in the code 'descending' and I think that should be 'ascending' to make it oldest date to newest date? I could not tell that it was actually working... I put my cursor into another table of data that was newest to oldest and invoked your macro and then could see that yes, it works. It's just backwards.

Thanks, might need more help to do some more stuff.
 
Upvote 0
Sektor, your code works for sorting that one column. But I need for it select not only that column, to the end of the data as you have it, but then go from that point ten columns over to the right (a total of 11 columns will be selected), and then do the sort on Column A, ascending.

Thanks to you and anyone who can help here.
 
Upvote 0

Forum statistics

Threads
1,224,518
Messages
6,179,248
Members
452,900
Latest member
LisaGo

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