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

Im writing a fiddly macro that seems to have a few problems with blan
rows.

Basically, my code is cycling through the rows in a spreadsheet an
deleting certain rows.

The code im using for this is :
Rows(n).Entirerow.Delete

Great!

Trouble is, i need to go through the rows at the end of the loop an
delete out all of the blank space rows left behind.

Im doing this as follows:


Code
-------------------

Lastrow = Activesheet.UsedRange.Rows - 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

-------------------


Is there a better way of getting rid of the rows rather than looping
Its just my code is taking forever.

Cheer

--
Message posted from http://www.ExcelForum.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 12
Default Removing Blank Rows?

I'd try this:

---------------------------------------
Lastrow = Activesheet.UsedRange.Rows - 1 + _
ActiveSheet.UsedRange.Rows.Count
Application.ScreenUpdating = False
r = Lastrow
Do While r = 1
If Application.CountA(Rows(r)) = 0 Then
Rows(r).delete
Else
r = r - 1
Loop


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Removing Blank Rows?

But isnt this doing exactly what my code is doing?

I cannot see how that would speed it up

--
Message posted from http://www.ExcelForum.com

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Removing Blank Rows?

andycharger,

The code will not run the way you posted it.
1. The first line of your code has a syntax error.
Remove the "s" from the end of Rows so it looks like...

LastRow = Activesheet.UsedRange.Row - 1 + _
ActiveSheet.UsedRange.Rows.Count

2. The "End If" should be removed.

'-------------------------------------
Once the code runs, then you can probably speed it up
by finding the last row with data instead of using the last
row of the used range. The last row with data can be
determined by calling the following function like this...

LastRow = GetBottomRow(ActiveSheet)

'=================================================
' GetBottomRow() Function
' Aug 31, 2001 - Created by Jim Cone
' Returns the number of the last worksheet row with data.
' If the sheet is blank it returns 0.
'=================================================
Function GetBottomRow(ByRef TheSheet as Worksheet) As Long
On Error GoTo NoRow
If TheSheet.FilterMode Then TheSheet.ShowAllData
GetBottomRow = TheSheet.Cells.Find(what:="*", SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row
Exit Function
NoRow:
GetBottomRow = 0
End Function

'-------------------------------------------------------------

Regards,
Jim Cone
San Francisco, CA

"andycharger " wrote in message ...
Im writing a fiddly macro that seems to have a few problems with blank rows.
Basically, my code is cycling through the rows in a spreadsheet and
deleting certain rows.
The code im using for this is :
Rows(n).Entirerow.Delete
Great!
Trouble is, i need to go through the rows at the end of the loop and
delete out all of the blank space rows left behind.
Im doing this as follows:
Code:
--------------------

Lastrow = Activesheet.UsedRange.Rows - 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
--------------------
Is there a better way of getting rid of the rows rather than looping?
Its just my code is taking forever.
Cheers


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
Removing blank cells in rows of data Andy in Edinburgh[_2_] Excel Worksheet Functions 8 September 8th 08 06:12 PM
Removing blank columns and rows from worksheet therrin Excel Discussion (Misc queries) 1 March 27th 08 06:56 PM
Removing Blank Rows ? Robert11 New Users to Excel 3 November 13th 06 03:07 PM
Removing blank rows in a worksheet Louise Excel Worksheet Functions 6 May 26th 05 02:21 PM
Removing unused or blank rows and columns Mark F Excel Discussion (Misc queries) 2 December 23rd 04 02:39 AM


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