Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default 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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default 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
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default 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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default 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





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
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
Delete empty rows maba Excel Programming 3 August 18th 05 08:38 AM
Delete empty rows ian123[_15_] Excel Programming 1 December 14th 03 02:35 PM


All times are GMT +1. The time now is 11:01 AM.

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"