Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
G G is offline
external usenet poster
 
Posts: 52
Default how to I sort and keep blank lines in between data

How do I sort data while keeping a blank line in between the data.

ex.

dogs
x
cats
x
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 110
Default how to I sort and keep blank lines in between data

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
filtering: sometimes data below blank lines is &isnt available? Allison Excel Worksheet Functions 2 February 20th 10 03:42 AM
Inserting numerous blank lines between specific rows of data Deb Excel Discussion (Misc queries) 5 December 22nd 09 05:01 PM
Sort data with blank rows dividing data Sheila Excel Discussion (Misc queries) 5 November 21st 08 06:54 PM
Do not show lack of data as a zero on graph lines, leave blank Just Joe Charts and Charting in Excel 1 February 15th 06 08:12 PM
how to automatically insert blank lines in between non-blank lines No Name Excel Programming 2 November 17th 03 03:40 PM


All times are GMT +1. The time now is 11:50 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"