Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Need macro to remove blank rows

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob


  #3   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

Thank you for your help! I sincerely appreciate it. Forgive me for not
checking Excel's Help file. I wasn't aware that it contained code snipets.

It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. Is
there a way to also test for cells that contain just a single space (i.e.,
LEN=1) and if true, delete those rows, too?
Thanks again for your help.

Regards, Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob



  #4   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

I just realized that if I simply insert:

If Len(currentCell.Value)=1 Then
currentCell.EntireRow.Delete
End If

after the first IF block, that should do the trick. Agree, or is there a
more elegant way to do it?

Thanks again.
Regards, Bob

"Bob" wrote:

Thank you for your help! I sincerely appreciate it. Forgive me for not
checking Excel's Help file. I wasn't aware that it contained code snipets.

It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. Is
there a way to also test for cells that contain just a single space (i.e.,
LEN=1) and if true, delete those rows, too?
Thanks again for your help.

Regards, Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob



  #5   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

Please ignore my last post. I don't know what I was thinking.
I simply changed:

If Len(currentCell.Value)=1 Then
to
If Len(currentCell.Value)<=1 Then

I don't know why, but when I run the macro once, SOME rows with cells whose
LEN<=1 still remain! When I run the macro a second time, it then catches and
removes those remaining rows.
Do you have any idea why I need to run the macro twice for it to truly
complete the job?
Thanks again.
Bob



"Bob" wrote:

I just realized that if I simply insert:

If Len(currentCell.Value)=1 Then
currentCell.EntireRow.Delete
End If

after the first IF block, that should do the trick. Agree, or is there a
more elegant way to do it?

Thanks again.
Regards, Bob

"Bob" wrote:

Thank you for your help! I sincerely appreciate it. Forgive me for not
checking Excel's Help file. I wasn't aware that it contained code snipets.

It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. Is
there a way to also test for cells that contain just a single space (i.e.,
LEN=1) and if true, delete those rows, too?
Thanks again for your help.

Regards, Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob




  #6   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. So I
modified the line:
If Len(currentCell.Value)=1 Then
to
If Len(currentCell.Value)<=1 Then

Also, I don't know why, but when I run the macro the first time, SOME rows
with cells whose LEN<=1 still remain! When I run the macro a second time, it
then catches and removes those remaining rows.
Do you have any idea why I need to run the macro twice for it to truly
complete the job?
Thanks again.
Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 244
Default Need macro to remove blank rows

You could try len(trim(currentcell.value)) which would remove any
offending spaces - but the macro SHOULD delete all rows in the range
first time through - you could always set the macro up to run twice
(for DoubleCheck=1 to 2:DoMacro:Next)
Bob wrote:
It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. So I
modified the line:
If Len(currentCell.Value)=1 Then
to
If Len(currentCell.Value)<=1 Then

Also, I don't know why, but when I run the macro the first time, SOME rows
with cells whose LEN<=1 still remain! When I run the macro a second time, it
then catches and removes those remaining rows.
Do you have any idea why I need to run the macro twice for it to truly
complete the job?
Thanks again.
Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob




  #8   Report Post  
Posted to microsoft.public.excel.programming
Bob Bob is offline
external usenet poster
 
Posts: 972
Default Need macro to remove blank rows

I appreciate the suggestion. I will give it a try.
Thanks again for all your help.
Regards, Bob


" wrote:

You could try len(trim(currentcell.value)) which would remove any
offending spaces - but the macro SHOULD delete all rows in the range
first time through - you could always set the macro up to run twice
(for DoubleCheck=1 to 2:DoMacro:Next)
Bob wrote:
It turns out that some of the cells in column H contain a space followed by
some data, while others contain just a single space and nothing else. So I
modified the line:
If Len(currentCell.Value)=1 Then
to
If Len(currentCell.Value)<=1 Then

Also, I don't know why, but when I run the macro the first time, SOME rows
with cells whose LEN<=1 still remain! When I run the macro a second time, it
then catches and removes those remaining rows.
Do you have any idea why I need to run the macro twice for it to truly
complete the job?
Thanks again.
Bob


" wrote:

This is ALMOST given in the Excel help file


Set currentCell = Worksheets("Sheet1").Range("H2")
for each cell in range("H2:H1000")
Set nextCell = currentCell.Offset(1, 0)
If Len(currentCell.Value)=0 Then
currentCell.EntireRow.Delete
End If
Set currentCell = nextCell
Next


Bob wrote:
I have a 1-column spreadsheet that contains data in column H. Some rows in
column H contain no data (i.e., its blank). I need help in writing a macro
that, starting with cell H2, will examine each cell in column H and
automatically delete a row where no data exists. The macro would terminate
after reaching row 1000.
I would greatly appreciate any help. Thanks.
Bob




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
Macro to Automatically remove blank rows Jack Wood Excel Discussion (Misc queries) 4 May 26th 09 08:43 PM
Remove blank rows without hiding them peter.thompson[_40_] Excel Programming 1 January 12th 06 09:38 PM
remove or hide blank rows Erik Beijlen via OfficeKB.com Excel Discussion (Misc queries) 1 February 1st 05 01:17 PM
Remove blank rows from combobox Steph[_3_] Excel Programming 1 June 25th 04 05:37 PM
remove all blank or empty rows [email protected] [email protected] Excel Programming 8 January 18th 04 07:55 PM


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