Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Deleting blank rows

Hi,

I am writing a macro to delete the entire row if all the cells are blank.
For example, in a range which 10 rows by 3 columns. Data in the first column
is 2 rows deep, 2nd column - 1 row, 3rd column - 3 rows. I want the macro
to delete rows 4 through to 10.

This is what I tried:

Dim c As Range
Dim myString As String

For Each c In Range("A1:A10").Cells
myString = c & c.Offset(0, 1) & c.Offset(0, 2)
If Len(myString) = 0 Then
c.EntireRow.Delete
End If
Next c

What happens is that only half the blank rows are deleted. It seems as
though after the first row is deleted 'Next c' skips a row. What am I doing
wrong?

Regards,
Michael


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Deleting blank rows

Dim c As Range
Dim myString As String
Dim i as Long

For i = 10 to 1 step -1
set c = Cells(i,1)
myString = c & c.Offset(0, 1) & c.Offset(0, 2)
If Len(myString) = 0 Then
c.EntireRow.Delete
End If
Next c

--
Regards,
Tom Ogilvy

"Michael Chang" wrote in message
...
Hi,

I am writing a macro to delete the entire row if all the cells are blank.
For example, in a range which 10 rows by 3 columns. Data in the first

column
is 2 rows deep, 2nd column - 1 row, 3rd column - 3 rows. I want the macro
to delete rows 4 through to 10.

This is what I tried:

Dim c As Range
Dim myString As String

For Each c In Range("A1:A10").Cells
myString = c & c.Offset(0, 1) & c.Offset(0, 2)
If Len(myString) = 0 Then
c.EntireRow.Delete
End If
Next c

What happens is that only half the blank rows are deleted. It seems as
though after the first row is deleted 'Next c' skips a row. What am I

doing
wrong?

Regards,
Michael




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Deleting blank rows

Delete from the bottom, up.

Mike F
"Michael Chang" wrote in message
...
Hi,

I am writing a macro to delete the entire row if all the cells are blank.
For example, in a range which 10 rows by 3 columns. Data in the first

column
is 2 rows deep, 2nd column - 1 row, 3rd column - 3 rows. I want the macro
to delete rows 4 through to 10.

This is what I tried:

Dim c As Range
Dim myString As String

For Each c In Range("A1:A10").Cells
myString = c & c.Offset(0, 1) & c.Offset(0, 2)
If Len(myString) = 0 Then
c.EntireRow.Delete
End If
Next c

What happens is that only half the blank rows are deleted. It seems as
though after the first row is deleted 'Next c' skips a row. What am I

doing
wrong?

Regards,
Michael




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 blank rows Rafeek Excel Discussion (Misc queries) 5 August 27th 11 03:20 PM
deleting blank rows KRK New Users to Excel 3 June 27th 09 12:51 PM
Deleting Blank Rows. GEM Excel Discussion (Misc queries) 3 April 15th 09 04:18 PM
Deleting Blank Rows Reeni New Users to Excel 4 December 15th 05 01:56 AM
DELETING BLANK ROWS Robert Lowe Excel Programming 3 August 30th 04 10:04 PM


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