Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Delete blank rows if more than one

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Delete blank rows if more than one

Use the below macro. If you are new to macros set the Security level to
low/medium in (Tools|Macro|Security). From workbook launch VBE using
short-key Alt+F11. From menu 'Insert' a module and paste the below code.
Save. Get back to Workbook. Run macro from Tools|Macro|Run <selected macro()

Sub Delete2EmptyRows()
Dim lngTemp As Long, lngRow As Long
For lngRow = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If WorksheetFunction.CountBlank(Rows(lngRow)) = Columns.Count Then
If lngTemp = lngRow + 1 Then Rows(lngTemp).Delete
lngTemp = lngRow
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Kjellk" wrote:

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.

  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 10
Default Delete blank rows if more than one

Hi
Just perfect!
Regards
Kjell

"Jacob Skaria" wrote:

Use the below macro. If you are new to macros set the Security level to
low/medium in (Tools|Macro|Security). From workbook launch VBE using
short-key Alt+F11. From menu 'Insert' a module and paste the below code.
Save. Get back to Workbook. Run macro from Tools|Macro|Run <selected macro()

Sub Delete2EmptyRows()
Dim lngTemp As Long, lngRow As Long
For lngRow = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If WorksheetFunction.CountBlank(Rows(lngRow)) = Columns.Count Then
If lngTemp = lngRow + 1 Then Rows(lngTemp).Delete
lngTemp = lngRow
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Kjellk" wrote:

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.

  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,520
Default Delete blank rows if more than one

Cheers.

If this post helps click Yes
---------------
Jacob Skaria


"Kjellk" wrote:

Hi
Just perfect!
Regards
Kjell

"Jacob Skaria" wrote:

Use the below macro. If you are new to macros set the Security level to
low/medium in (Tools|Macro|Security). From workbook launch VBE using
short-key Alt+F11. From menu 'Insert' a module and paste the below code.
Save. Get back to Workbook. Run macro from Tools|Macro|Run <selected macro()

Sub Delete2EmptyRows()
Dim lngTemp As Long, lngRow As Long
For lngRow = Cells(Rows.Count, 1).End(xlUp).Row To 1 Step -1
If WorksheetFunction.CountBlank(Rows(lngRow)) = Columns.Count Then
If lngTemp = lngRow + 1 Then Rows(lngTemp).Delete
lngTemp = lngRow
End If
Next
End Sub


If this post helps click Yes
---------------
Jacob Skaria


"Kjellk" wrote:

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.

  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 3,346
Default Delete blank rows if more than one

Hi,

Don't really need a macro, but you could record these steps if you wanted:

1. Suppose column A contains data except when you have blank rows, then in
an empty column, lets say D, in D2 enter the formula
=IF(AND(A1="",A2=""),"Y",1)
and copy it down as far as you data goes.
2. Select this range of formulas and press F5, Special, Formulas, and
unchech all except Text, click OK
3. Press Ctrl+- (control minus) and choose Entire row, OK.
4. Clear the formulas from column D

The code to do this runs extremely fast

Sub DeleteExcess()
Dim Bottom As Long
Bottom = [A65536].End(xlUp).Row
Range("D2:D" & Bottom).Select
Selection = "=IF(AND(A2="""",A1=""""),""Y"",1)"
Selection.SpecialCells(xlCellTypeFormulas, 2).EntireRow.Delete
Columns("D:D").ClearContents
End Sub

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Kjellk" wrote:

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.



  #6   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 553
Default Delete blank rows if more than one

Instead of =IF(AND(A1="",A2=""),"Y",1) in the first point, use:
=IF(AND(isblank(A1),isblank(A2)),"Y",1)

"Shane Devenshire" wrote:

Hi,

Don't really need a macro, but you could record these steps if you wanted:

1. Suppose column A contains data except when you have blank rows, then in
an empty column, lets say D, in D2 enter the formula
=IF(AND(A1="",A2=""),"Y",1)
and copy it down as far as you data goes.
2. Select this range of formulas and press F5, Special, Formulas, and
unchech all except Text, click OK
3. Press Ctrl+- (control minus) and choose Entire row, OK.
4. Clear the formulas from column D

The code to do this runs extremely fast

Sub DeleteExcess()
Dim Bottom As Long
Bottom = [A65536].End(xlUp).Row
Range("D2:D" & Bottom).Select
Selection = "=IF(AND(A2="""",A1=""""),""Y"",1)"
Selection.SpecialCells(xlCellTypeFormulas, 2).EntireRow.Delete
Columns("D:D").ClearContents
End Sub

--
If this helps, please click the Yes button.

Cheers,
Shane Devenshire


"Kjellk" wrote:

I have groups of data divided by blank rows. It is not consistent- sometimes
its one row, sometimes it is more. I want to to keep one blank row between
every group and remove the others.

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
Delete blank rows Marie Bayes Excel Discussion (Misc queries) 5 April 29th 09 01:59 PM
Delete blank rows JakeShipley2008 Excel Discussion (Misc queries) 2 October 30th 08 02:18 AM
Delete all blank rows... bourbon84 Excel Discussion (Misc queries) 2 October 4th 06 02:13 PM
delete blank rows Pam C Excel Discussion (Misc queries) 1 January 17th 06 07:13 PM
How to delete blank rows John Mansfield Excel Discussion (Misc queries) 3 April 27th 05 11:48 PM


All times are GMT +1. The time now is 08:49 PM.

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

About Us

"It's about Microsoft Excel"