Delete 1 Blank of 2 Consecutive Blank Rows

hip2b2

Board Regular
Joined
May 5, 2003
Messages
135
Office Version
  1. 2019
Platform
  1. Windows
I have a small report but the format is somewhat irregular.

The report is several lines of header text
Followed by 1 or more empty rows
Followed by 1 or more consecutive rows of data
Followed by 1 or more empty rows
etc.

I have been looking for VBA code (with no luck) to reduce the 1 or more empty rows to only 1 empty row separating the different data sets..

As always any help is appreciated.

hip
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
Assuming column A can be used to establish the blank rows :
VBA Code:
Sub v()
Dim rng As Range, a As Range
Set rng = Range("A1:A" & Cells(Rows.Count, "A").End(3).Row).SpecialCells(xlCellTypeBlanks)
For Each a In rng.Areas
    If a.Count > 1 Then a(2).Resize(a.Count - 1).EntireRow.Delete
Next
End Sub
 
Upvote 0
Slightly tweaking footoo's code to move the .Areas up one code line & eliminate the need to declare a second range ..
VBA Code:
Sub ReduceBlanks()
  Dim rA As Range
  For Each rA In Range("A1", Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlBlanks).Areas
    If rA.Rows.Count > 1 Then rA.Resize(rA.Rows.Count - 1).EntireRow.Delete
  Next rA
End Sub
 
Upvote 0
Peter and footoo

Thank you both for taking the time to provie a solution.

hip
 
Upvote 0
You're welcome. Glad we could help. Thanks for the follow-up. :)

(Perhaps you could also take a look here?)
 
Upvote 0

Forum statistics

Threads
1,214,642
Messages
6,120,701
Members
448,980
Latest member
CarlosWin

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