Home |
Search |
Today's Posts |
|
#1
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
How do I sort data while keeping a blank line in between the data.
ex. dogs x cats x |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
I'm sure someone will have a better solution, but this would be mine...
This code works from highlighting the section (without header rows) that you want sorted, and assumes that the blank cells have no text at all in them. It also uses the column next to your selection - you would have to change the code if you need to use another column. Sub SortWithBlank() Dim c As Object Set c = ActiveCell For Each c In Selection If c.Value = "" Then c.Offset(0, 1).Value = c.Offset(-1, 0).Value & 1 Else c.Offset(0, 1).Value = c.Value End If Next c Range(Cells(Selection.Row, Selection.Column), Cells(Selection.Row + Selection.Rows.Count - 1, Selection.Column + 1)).Select Selection.Sort Key1:=Cells(Selection.Row + 1, Selection.Column + 1), Order1:=xlAscending, Header:=xlNo, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, DataOption1:=xlSortNormal Range(Cells(Selection.Row, Selection.Column + 1), Cells(Selection.Row + Selection.Rows.Count - 1, Selection.Column + 1)).ClearContents Range("A1").Select End Sub "G" wrote: How do I sort data while keeping a blank line in between the data. ex. dogs x cats x |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
filtering: sometimes data below blank lines is &isnt available? | Excel Worksheet Functions | |||
Inserting numerous blank lines between specific rows of data | Excel Discussion (Misc queries) | |||
Sort data with blank rows dividing data | Excel Discussion (Misc queries) | |||
Do not show lack of data as a zero on graph lines, leave blank | Charts and Charting in Excel | |||
how to automatically insert blank lines in between non-blank lines | Excel Programming |