ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   delete empty rows of a sheet (https://www.excelbanter.com/excel-programming/353435-delete-empty-rows-sheet.html)

p. panter

delete empty rows of a sheet
 
Hello,

how can I delete just empty rows of a sheet

with the following code I can just delete empty cells and after that the
rows are not the same as before (have different values).

Sub emptyCellsDelete()
sheet1.Cells.Range("A6:M155").SpecialCells _
(xlCellTypeBlanks).Delete shift:=xlUp

End Sub



Ron de Bruin

delete empty rows of a sheet
 
Hi

Try this example for row 1 - 100

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If Application.CountA(.Rows(Lrow)) = 0 Then .Rows(Lrow).Delete
'This will delete the row if the whole row is empty (all columns)
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub









--
Regards Ron de Bruin
http://www.rondebruin.nl


"p. panter" wrote in message ...
Hello,

how can I delete just empty rows of a sheet

with the following code I can just delete empty cells and after that the rows are not the same as before (have different values).

Sub emptyCellsDelete()
sheet1.Cells.Range("A6:M155").SpecialCells _
(xlCellTypeBlanks).Delete shift:=xlUp

End Sub





Dave Peterson

delete empty rows of a sheet
 
One more thing for your sample code. There have been a few posts that complain
about macros taking too long when the window is in pagebreak view.



Option Explicit
Sub testme()

Dim CalcMode As Long
Dim ViewMode As Long

Application.ScreenUpdating = False

CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

ActiveSheet.DisplayPageBreaks = False

'do the work

'put things back to what they were
Application.Calculation = CalcMode
ActiveWindow.View = ViewMode

End Sub

Ron de Bruin wrote:

Hi

Try this example for row 1 - 100

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If Application.CountA(.Rows(Lrow)) = 0 Then .Rows(Lrow).Delete
'This will delete the row if the whole row is empty (all columns)
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl

"p. panter" wrote in message ...
Hello,

how can I delete just empty rows of a sheet

with the following code I can just delete empty cells and after that the rows are not the same as before (have different values).

Sub emptyCellsDelete()
sheet1.Cells.Range("A6:M155").SpecialCells _
(xlCellTypeBlanks).Delete shift:=xlUp

End Sub



--

Dave Peterson

knowtrump[_19_]

delete empty rows of a sheet
 

P. I am probably missing some subtlety in your requirements but th
following
will remove empty rows albeit with a simplistic and work/typin
intensive macro.
Sub Macro2()
'

Dim n As Long, xxxxx As Long
With ActiveSheet

xxxxx = Cells(Rows.Count, "A").End(xlUp).Row
For n = xxxxx To 6 Step -1

If (.Cells(n, "A").Value) = "" And (.Cells(n, "B").Value) = "" An
(.Cells(n, "C").Value) = "" _
And (.Cells(n, "D").Value) = "" And (.Cells(n, "E").Value) = "" Then

.Rows(n).Delete
End If
Next n
End With

End Sub

For your particular requirement the "Ands" have to include A to M. Yo
can use n = 155 to 6 Step -1 rather than xxxxx. If a row is almos
blank but contains say a single not empty cell the row will not b
deleted. I'm sure there are better ways but this should work

--
knowtrum
-----------------------------------------------------------------------
knowtrump's Profile: http://www.excelforum.com/member.php...fo&userid=1966
View this thread: http://www.excelforum.com/showthread.php?threadid=51293


Ron de Bruin

delete empty rows of a sheet
 
Hi Dave

about macros taking too long when the window is in pagebreak view

Good point

I will add this to my examples


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Dave Peterson" wrote in message ...
One more thing for your sample code. There have been a few posts that complain
about macros taking too long when the window is in pagebreak view.



Option Explicit
Sub testme()

Dim CalcMode As Long
Dim ViewMode As Long

Application.ScreenUpdating = False

CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

ActiveSheet.DisplayPageBreaks = False

'do the work

'put things back to what they were
Application.Calculation = CalcMode
ActiveWindow.View = ViewMode

End Sub

Ron de Bruin wrote:

Hi

Try this example for row 1 - 100

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If Application.CountA(.Rows(Lrow)) = 0 Then .Rows(Lrow).Delete
'This will delete the row if the whole row is empty (all columns)
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl

"p. panter" wrote in message ...
Hello,

how can I delete just empty rows of a sheet

with the following code I can just delete empty cells and after that the rows are not the same as before (have different
values).

Sub emptyCellsDelete()
sheet1.Cells.Range("A6:M155").SpecialCells _
(xlCellTypeBlanks).Delete shift:=xlUp

End Sub



--

Dave Peterson




Ron de Bruin

delete empty rows of a sheet
 
I will add this to my example page

Done
http://www.rondebruin.nl/delete.htm



--
Regards Ron de Bruin
http://www.rondebruin.nl


"Ron de Bruin" wrote in message ...
Hi Dave

about macros taking too long when the window is in pagebreak view

Good point

I will add this to my examples


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Dave Peterson" wrote in message ...
One more thing for your sample code. There have been a few posts that complain
about macros taking too long when the window is in pagebreak view.



Option Explicit
Sub testme()

Dim CalcMode As Long
Dim ViewMode As Long

Application.ScreenUpdating = False

CalcMode = Application.Calculation
Application.Calculation = xlCalculationManual

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

ActiveSheet.DisplayPageBreaks = False

'do the work

'put things back to what they were
Application.Calculation = CalcMode
ActiveWindow.View = ViewMode

End Sub

Ron de Bruin wrote:

Hi

Try this example for row 1 - 100

Sub Example2()
Dim Lrow As Long
Dim CalcMode As Long
Dim StartRow As Long
Dim EndRow As Long
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = 100
For Lrow = EndRow To StartRow Step -1
If Application.CountA(.Rows(Lrow)) = 0 Then .Rows(Lrow).Delete
'This will delete the row if the whole row is empty (all columns)
Next
End With
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub

--
Regards Ron de Bruin
http://www.rondebruin.nl

"p. panter" wrote in message ...
Hello,

how can I delete just empty rows of a sheet

with the following code I can just delete empty cells and after that the rows are not the same as before (have different
values).

Sub emptyCellsDelete()
sheet1.Cells.Range("A6:M155").SpecialCells _
(xlCellTypeBlanks).Delete shift:=xlUp

End Sub



--

Dave Peterson







All times are GMT +1. The time now is 02:01 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com