Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Delete Empty Rows Macro

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default Delete Empty Rows Macro

Sub DeleteEmptyRows()
''only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For R = LastRow To 1 Step -1
If Application.CountA(Rows(R)) = 0 Then
Rows(R).Delete
End If
Next R
End Sub


Gord Dibben MS Excel MVP

On Thu, 21 Aug 2008 19:57:02 -0700, yepiknowiam
wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Delete Empty Rows Macro

Everything works fine, but have another question. If I open up a different
workbook, the macro is not listed. Is there a way to save it or import it so
any workbook I open up, I will have access to it?

"Gord Dibben" wrote:

Sub DeleteEmptyRows()
''only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For R = LastRow To 1 Step -1
If Application.CountA(Rows(R)) = 0 Then
Rows(R).Delete
End If
Next R
End Sub


Gord Dibben MS Excel MVP

On Thu, 21 Aug 2008 19:57:02 -0700, yepiknowiam
wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Delete Empty Rows Macro

Lots of people who have this kind of useful macro create a workbook named
personal.xls (.xlsm). Then they store that workbook in their XLStart folder.

That way, excel will open this macro workbook whenever excel opens.

In fact, most people have this personal.xls hidden -- so it doesn't get in the
way of real work.

Then you can just open any workbook,
hit alt-f8 (tools|macro|macros in xl2003 menus)
select the macro and run it.



yepiknowiam wrote:

Everything works fine, but have another question. If I open up a different
workbook, the macro is not listed. Is there a way to save it or import it so
any workbook I open up, I will have access to it?

"Gord Dibben" wrote:

Sub DeleteEmptyRows()
''only if entire row is blank
LastRow = ActiveSheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
For R = LastRow To 1 Step -1
If Application.CountA(Rows(R)) = 0 Then
Rows(R).Delete
End If
Next R
End Sub


Gord Dibben MS Excel MVP

On Thu, 21 Aug 2008 19:57:02 -0700, yepiknowiam
wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.




--

Dave Peterson
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Delete Empty Rows Macro

Hi,

The following macro should help. Take note of the comment re the column.

Ensure that you backup your workbook in case it does not do exactly what you
want.

Sub Delete_Rows()

Dim rngA As Range
Dim c As Range
Dim i As Long
Dim colCount As Long

'Assumes that column A will have data in the last cell
'within the range being tested. Otherwise change "A"
'to a column that does have data in last cell of total
'range being tested.

Set rngA = ActiveSheet.Range(Cells(1, "A"), _
Cells(Rows.Count, "A").End(xlUp))

colCount = ActiveSheet.Columns.Count

'Work from bottom when deleting rows
With rngA
For i = .Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Range(Cells(i, 1), _
Cells(i, colCount))) = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub


--
Regards,

OssieMac


"yepiknowiam" wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Delete Empty Rows Macro

Thanks. I'll experiment with both of these and see how they work.

"OssieMac" wrote:

Hi,

The following macro should help. Take note of the comment re the column.

Ensure that you backup your workbook in case it does not do exactly what you
want.

Sub Delete_Rows()

Dim rngA As Range
Dim c As Range
Dim i As Long
Dim colCount As Long

'Assumes that column A will have data in the last cell
'within the range being tested. Otherwise change "A"
'to a column that does have data in last cell of total
'range being tested.

Set rngA = ActiveSheet.Range(Cells(1, "A"), _
Cells(Rows.Count, "A").End(xlUp))

colCount = ActiveSheet.Columns.Count

'Work from bottom when deleting rows
With rngA
For i = .Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Range(Cells(i, 1), _
Cells(i, colCount))) = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub


--
Regards,

OssieMac


"yepiknowiam" wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,510
Default Delete Empty Rows Macro

Gord's reply is much better. It's completely generic. We posted
simultaneously but had I seen his reply first I would not have posted mine.

--
Regards,

OssieMac


"yepiknowiam" wrote:

Thanks. I'll experiment with both of these and see how they work.

"OssieMac" wrote:

Hi,

The following macro should help. Take note of the comment re the column.

Ensure that you backup your workbook in case it does not do exactly what you
want.

Sub Delete_Rows()

Dim rngA As Range
Dim c As Range
Dim i As Long
Dim colCount As Long

'Assumes that column A will have data in the last cell
'within the range being tested. Otherwise change "A"
'to a column that does have data in last cell of total
'range being tested.

Set rngA = ActiveSheet.Range(Cells(1, "A"), _
Cells(Rows.Count, "A").End(xlUp))

colCount = ActiveSheet.Columns.Count

'Work from bottom when deleting rows
With rngA
For i = .Rows.Count To 1 Step -1
If WorksheetFunction.CountA(Range(Cells(i, 1), _
Cells(i, colCount))) = 0 Then
.Cells(i).EntireRow.Delete
End If
Next i
End With
End Sub


--
Regards,

OssieMac


"yepiknowiam" wrote:

I have been looking for a macro that will delete any empty row. This
spreadsheet I work with generally has 3-4 empty rows after each section.

It doesn't have to be complex.

Thanks.

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
Delete empty rows with macro by John Walkenbach Steve G Excel Programming 2 August 3rd 07 01:47 PM
Delete Rows with Empty Cells with empty column 1 Scott Excel Programming 5 October 2nd 06 11:57 PM
How do I write a macro to delete all rows from the first empty ro. Jon M[_3_] Excel Programming 2 May 12th 05 06:01 PM
Cut and Paste macro based on criteria then delete empty rows samst Excel Programming 4 November 2nd 03 09:33 PM


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