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

Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Delete Blank rows

Thx William,
Much Better!!

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete Blank rows

Hi Sige,

(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)


In fact the usedrange starts at the first populated or formatted cell.

In an unused worksheet, format or populate a cell other than A1. In the
intermediate window type:
? UsedRange.Address
and see the result.

Can I get rid of those lines as well?


Try replacing:

For R = Rng.Rows.Count To 1 Step -1


with

For R = Rng.Row + Rng.Rows.Count - 1 To 1 Step -1


---
Regards,
Norman



"Sige" wrote in message
oups.com...
Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 206
Default Delete Blank rows

Perfect!
Sige



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Delete Blank rows

why do i get an object required error when i try this, ? UsedRange.Address,
in the immediate window?

--


Gary


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

(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)


In fact the usedrange starts at the first populated or formatted cell.

In an unused worksheet, format or populate a cell other than A1. In the
intermediate window type:
? UsedRange.Address
and see the result.

Can I get rid of those lines as well?


Try replacing:

For R = Rng.Rows.Count To 1 Step -1


with

For R = Rng.Row + Rng.Rows.Count - 1 To 1 Step -1


---
Regards,
Norman



"Sige" wrote in message
oups.com...
Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub





  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Delete Blank rows

Hi Gary,

? UsedRange.Address


Should be:

?ActiveSheet.UsedRange.Address

I typed rather than copy / pasted!

Thank you.

---
Regards,
Norman



"Gary Keramidas" wrote in message
...
why do i get an object required error when i try this, ?
UsedRange.Address, in the immediate window?

--


Gary


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

(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)


In fact the usedrange starts at the first populated or formatted cell.

In an unused worksheet, format or populate a cell other than A1. In the
intermediate window type:
? UsedRange.Address
and see the result.

Can I get rid of those lines as well?


Try replacing:

For R = Rng.Rows.Count To 1 Step -1


with

For R = Rng.Row + Rng.Rows.Count - 1 To 1 Step -1


---
Regards,
Norman



"Sige" wrote in message
oups.com...
Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub







  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Delete Blank rows

Maybe in the "Intermediate" window you don't need to qualify it <g. I
don't have one, so I can't say.

--
Regards,
Tom Ogilvy

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

? UsedRange.Address


Should be:

?ActiveSheet.UsedRange.Address

I typed rather than copy / pasted!

Thank you.

---
Regards,
Norman



"Gary Keramidas" wrote in message
...
why do i get an object required error when i try this, ?
UsedRange.Address, in the immediate window?

--


Gary


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

(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

In fact the usedrange starts at the first populated or formatted cell.

In an unused worksheet, format or populate a cell other than A1. In the
intermediate window type:
? UsedRange.Address
and see the result.

Can I get rid of those lines as well?

Try replacing:

For R = Rng.Rows.Count To 1 Step -1

with

For R = Rng.Row + Rng.Rows.Count - 1 To 1 Step -1


---
Regards,
Norman



"Sige" wrote in message
oups.com...
Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it

will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub









  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete Blank rows

Hi Gary

You must use it like this

? activesheet.UsedRange.Address


--
Regards Ron de Bruin
http://www.rondebruin.nl


"Gary Keramidas" wrote in message ...
why do i get an object required error when i try this, ? UsedRange.Address, in the immediate window?

--


Gary


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

(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)


In fact the usedrange starts at the first populated or formatted cell.

In an unused worksheet, format or populate a cell other than A1. In the intermediate window type:
? UsedRange.Address
and see the result.

Can I get rid of those lines as well?


Try replacing:

For R = Rng.Rows.Count To 1 Step -1


with

For R = Rng.Row + Rng.Rows.Count - 1 To 1 Step -1


---
Regards,
Norman



"Sige" wrote in message oups.com...
Hi There,

Chip's code to delete blank rows.
Situation:

If my first data starts appears in row 5 and row 1-4 are blank, it will
delete all blank lines but does not delete row 1-4. They are not part
of the usedrange apparently.
(I always thought usedrange = A1:LAST CELL, but seems to be FIRST
CELL:LASTCELL)

Can I get rid of those lines as well?

Cheers Sige

Public Sub DeleteBlankRows()

Dim R As Long
Dim C As Range
Dim Rng As Range

On Error GoTo EndMacro
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

If Selection.Rows.Count 1 Then
Set Rng = Selection
Else
Set Rng = ActiveSheet.UsedRange.Rows
End If
For R = Rng.Rows.Count To 1 Step -1
If Application.WorksheetFunction.CountA(Rng.Rows(R).E ntireRow) = 0
Then
Rng.Rows(R).EntireRow.Delete
End If
Next R

EndMacro:

Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic

End Sub







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
Delete all blank rows... bourbon84 Excel Discussion (Misc queries) 2 October 4th 06 02:13 PM
Delete blank rows Jim333[_8_] Excel Programming 4 September 4th 05 12:07 PM
Delete blank rows djh Excel Programming 2 October 26th 04 02:17 PM
Delete blank row only if 2 consecutive blank rows Amy Excel Programming 2 October 21st 04 05:24 PM
help delete blank rows Cletus Stripling Excel Programming 5 July 25th 03 08:47 PM


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