Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default finding empty rows and deleting

I have range of data that varies. The data has empty rows of data. I need to find the empty rows and delete them. Need help creating VBA code to do this.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 770
Default finding empty rows and deleting

I must have got this from Google Groups (archived NG postings, check it
out!) or Ron's web site. It deletes all blank rows in a sheet, actually any
row with a blank in column 1, same thing in your case. If you have some
blank rows outside your range of data that you want to keep, you'd have to
tailor.

Public Sub DeleteBlankRows()

'Ron De Bruin

Dim column_with_blanks As Long

column_with_blanks = 1

On Error Resume Next 'In case there are no blank rows

Columns(column_with_blanks).SpecialCells(xlCellTyp eBlanks).EntireRow.Delete
On Error GoTo 0

End Sub

hth,

Doug Glancy

"Ryan" wrote in message
...
I have range of data that varies. The data has empty rows of data. I need

to find the empty rows and delete them. Need help creating VBA code to do
this.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22,906
Default finding empty rows and deleting

Ryan

Delete entire rows based on blanks in your selected column.

Public Sub DeleteRowOnCell()
''delete any row that has a blank in selected column(s)
Set coltocheck = Application.InputBox(prompt:= _
"Select A Column", Type:=8)
' On Error Resume Next
coltocheck.SpecialCells(xlCellTypeBlanks).EntireRo w.Delete
ActiveSheet.UsedRange
End Sub

Assuming entire row has to be blank.

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
Next R
End Sub

Gord Dibben Excel MVP

On Wed, 21 Apr 2004 21:01:17 -0700, "Ryan"
wrote:

I have range of data that varies. The data has empty rows of data. I need to find the empty rows and delete them. Need help creating VBA code to do this.


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default finding empty rows and deleting

I've found that it's faster in Excel to insert a numbered column,
then sort the data column to drive empty rows to bottom of table,
then delete empty rows and rearrange the table back to the original order.
This is faster than walking the table (with code), finding blank rows and
deleting one at a time.

The following assumes your table starts in a1, adjust address values if your
column has header

Sub DeleteEmptyRows()
'insert new column 'a' and number it sequentially for sorting
Columns("A:A").Insert Shift:=xlToRight
Range("A1").FormulaR1C1 = "1"
Range("A2").FormulaR1C1 = "2"
Range("A3").FormulaR1C1 = "3"
Set StartRange1 = Range("a3")
Set EndRange1 = Range("B65536").End(xlUp).Offset(0, -1)
Range(StartRange1, EndRange1).DataSeries Rowcol:=xlColumns,
Type:=xlLinear, Date:=xlDay, Step:=1, Trend:=False
'sort by column 'B' to drive empty rows to bottom of column
Range("B1").Sort Key1:=Range("B1"), Order1:=xlAscending,
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
'delete empty rows
Set StartRange2 = Range("b1").End(xlDown).Offset(1, -1)
Set EndRange2 = Range("A65536").End(xlUp)
Range(StartRange2, EndRange2).EntireRow.Delete
'sort again by column 'A' to restore original order
Range("A1").Sort Key1:=Range("A1"), Order1:=xlAscending,
Header:=xlGuess, OrderCustom:=1, MatchCase:=False,
Orientation:=xlTopToBottom
'delete column 'A'
Columns("A:A").Delete
End Sub

hope this helps

"Ryan" wrote in message
...
I have range of data that varies. The data has empty rows of data. I need

to find the empty rows and delete them. Need help creating VBA code to do
this.


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
Deleting empty rows Felix New Users to Excel 1 February 3rd 09 07:48 AM
Deleting Rows Between Empty Cells Daren Excel Worksheet Functions 6 September 8th 08 04:19 PM
deleting empty rows EngelseBoer Excel Discussion (Misc queries) 3 September 7th 08 01:09 AM
Deleting All Empty Rows bodhisatvaofboogie Excel Discussion (Misc queries) 3 May 18th 06 12:36 PM
Deleting unwanted and empty rows... Jim Excel Discussion (Misc queries) 2 July 4th 05 11:12 PM


All times are GMT +1. The time now is 07:44 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"