Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - remove all empty rows in a worksheet


Hi!
is there a way in VBA to remove all empty rows in a worksheet
'Sheet1'?

Cheers
Juergen


--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile: http://www.excelforum.com/member.php...o&userid=25248
View this thread: http://www.excelforum.com/showthread...hreadid=499951

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA - remove all empty rows in a worksheet

Hi Juergen,

Try:

'=============
Public Sub Tester()
On Error Resume Next
Columns(1).SpecialCells(xlBlanks).EntireRow.Delete
On Error GoTo 0
End Sub
'<<=============


---
Regards,
Norman


"juergenkemeter"
<juergenkemeter.21fyyy_1136934901.6862@excelforu m-nospam.com wrote in
message news:juergenkemeter.21fyyy_1136934901.6862@excelfo rum-nospam.com...

Hi!
is there a way in VBA to remove all empty rows in a worksheet
'Sheet1'?

Cheers
Juergen


--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile:
http://www.excelforum.com/member.php...o&userid=25248
View this thread: http://www.excelforum.com/showthread...hreadid=499951



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA - remove all empty rows in a worksheet

Hi Juergen,

Or, better and less telegrammatic:

'=============
Public Sub Tester2()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

On Error Resume Next
SH.Columns(1).SpecialCells(xlBlanks).EntireRow.Del ete
On Error GoTo 0

End Sub
'<<=============

---
Regards,
Norman


"Norman Jones" wrote in message
...
Hi Juergen,

Try:

'=============
Public Sub Tester()
On Error Resume Next
Columns(1).SpecialCells(xlBlanks).EntireRow.Delete
On Error GoTo 0
End Sub
'<<=============


---
Regards,
Norman


"juergenkemeter"
<juergenkemeter.21fyyy_1136934901.6862@excelforu m-nospam.com wrote in
message
news:juergenkemeter.21fyyy_1136934901.6862@excelfo rum-nospam.com...

Hi!
is there a way in VBA to remove all empty rows in a worksheet
'Sheet1'?

Cheers
Juergen


--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile:
http://www.excelforum.com/member.php...o&userid=25248
View this thread:
http://www.excelforum.com/showthread...hreadid=499951





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default VBA - remove all empty rows in a worksheet


Hi,
I tried

Code:
--------------------

Public Sub Tester2()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

On Error Resume Next
SH.Columns("B:M").SpecialCells(xlBlanks).EntireRow .Delete
On Error GoTo 0

End Sub

--------------------


to delete all rows which have no value in range B to M. Somehow it does
nothing special...
I enclosed an example workbook.

cheers
Juergen


+-------------------------------------------------------------------+
|Filename: DeleteEmptyRow.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4206 |
+-------------------------------------------------------------------+

--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile: http://www.excelforum.com/member.php...o&userid=25248
View this thread: http://www.excelforum.com/showthread...hreadid=499951

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default VBA - remove all empty rows in a worksheet

Norman's code actually looked at one column to determine if the row is empty.

If you can't pick out a column that is always filled in whenever something in
that row is filled in, you could use something like:

Option Explicit
Public Sub Tester2a()
Dim WB As Workbook
Dim SH As Worksheet
Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

With SH
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
FirstRow = 1

For iRow = LastRow To FirstRow Step -1
If Application.CountA(.Rows(iRow)) = 0 Then
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub

If you really only wanted to check columns B:M (ignoring A and N:IV):

Option Explicit
Public Sub Tester2a()
Dim WB As Workbook
Dim SH As Worksheet
Dim LastRow As Long
Dim FirstRow As Long
Dim iRow As Long

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

With SH
LastRow = .Cells.SpecialCells(xlCellTypeLastCell).Row
FirstRow = 1

For iRow = LastRow To FirstRow Step -1
If Application.CountA _
(.Range(.Cells(iRow, "B"), .Cells(iRow, "M"))) = 0 Then
.Rows(iRow).Delete
End If
Next iRow
End With

End Sub


juergenkemeter wrote:

Hi,
I tried

Code:
--------------------

Public Sub Tester2()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

On Error Resume Next
SH.Columns("B:M").SpecialCells(xlBlanks).EntireRow .Delete
On Error GoTo 0

End Sub

--------------------

to delete all rows which have no value in range B to M. Somehow it does
nothing special...
I enclosed an example workbook.

cheers
Juergen

+-------------------------------------------------------------------+
|Filename: DeleteEmptyRow.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4206 |
+-------------------------------------------------------------------+

--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile: http://www.excelforum.com/member.php...o&userid=25248
View this thread: http://www.excelforum.com/showthread...hreadid=499951


--

Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA - remove all empty rows in a worksheet

Hi Juergen,

You appear to have moved the goal posts: your original question was to
remove all empty rows.

However, try:

'=============
Public Sub Tester3()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

On Error Resume Next
SH.Columns("B").SpecialCells(xlBlanks).EntireRow.D elete
On Error GoTo 0

End Sub
'<<=============


If, however, column B cannot be used to define empty rows, post back with
more detail.


---
Regards,
Norman


"juergenkemeter"
<juergenkemeter.21g1ip_1136938205.9638@excelforu m-nospam.com wrote in
message news:juergenkemeter.21g1ip_1136938205.9638@excelfo rum-nospam.com...

Hi,
I tried

Code:
--------------------

Public Sub Tester2()
Dim WB As Workbook
Dim SH As Worksheet

Set WB = ActiveWorkbook '<<==== CHANGE
Set SH = WB.Sheets("Sheet1") '<<==== CHANGE

On Error Resume Next
SH.Columns("B:M").SpecialCells(xlBlanks).EntireRow .Delete
On Error GoTo 0

End Sub

--------------------


to delete all rows which have no value in range B to M. Somehow it does
nothing special...
I enclosed an example workbook.

cheers
Juergen


+-------------------------------------------------------------------+
|Filename: DeleteEmptyRow.zip |
|Download: http://www.excelforum.com/attachment.php?postid=4206 |
+-------------------------------------------------------------------+

--
juergenkemeter
------------------------------------------------------------------------
juergenkemeter's Profile:
http://www.excelforum.com/member.php...o&userid=25248
View this thread: http://www.excelforum.com/showthread...hreadid=499951



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default VBA - remove all empty rows in a worksheet

Hi Juergen,

If, however, column B cannot be used to define empty rows, post back with
more detail.


Given, however, Dave's intervening and comprehensive response, that should
be unnecessary.

---
Regards,
Norman




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
how to remove empty rows? Joe Excel Discussion (Misc queries) 2 January 6th 08 05:10 PM
How do I remove empty Rows Rodders Excel Discussion (Misc queries) 2 January 12th 07 12:04 PM
Remove empty rows in excel? Clbmgr Excel Discussion (Misc queries) 6 December 2nd 04 02:02 AM
remove all blank or empty rows [email protected] [email protected] Excel Programming 8 January 18th 04 07:55 PM
Remove empty rows Kaj Pedersen Excel Programming 15 November 2nd 03 07:22 PM


All times are GMT +1. The time now is 01:55 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"