HELP WITH SMALL MACRO PLEASE

BAS872

New Member
Joined
Sep 17, 2002
Messages
5
I would appreciate help with a macro to sort data in a small table.

Say the table is in range A1:F15

Problem:
Sometimes not all rows contain data. The last one, two or more (up to 6 or 7)rows may be empty. When Excel sorts the whole table it places empty rows on top and it leaves corresponding gaps in the chart associated with the table!

Instead of writing the range A1:F15 in the macro, what line of code can I use so that Excel selects only the rows that contain data?

The empty rows are always the ones at the bottom of the table. And, as I say, it may be anywhere between the last one and the last seven rows that will be empty.

I would appreciate any help. I am not a programmer...as if you couldn't tell!

Thanks
 

Excel Facts

What do {} around a formula in the formula bar mean?
{Formula} means the formula was entered using Ctrl+Shift+Enter signifying an old-style array formula.
Your macro will look something like this. Modify for the column to sort by, and whether you want to sort ascending or descending.

Sub SortList()
Dim sList As Range
Set sList = Range(("A1"), Range("F65536").End(xlUp))
sList.Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
 
Upvote 0
Off message, but just FYI - excel will only chart visable cells, so you can remove offending values from a chart (e.g. zeros / blanks) by setting up a filter on the chart's data range to filter them out...

Paddy
 
Upvote 0

Forum statistics

Threads
1,213,506
Messages
6,114,024
Members
448,543
Latest member
MartinLarkin

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