LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Problem with deleting blank rows or last row

Hi. I am using Excel 2007 and am having a problem deleting blank rows
or finding the last row.

When I am in the spreadsheet and press Ctrl-End, it goes to row 660.
However, when I get the number of rows for the ActiveSheet
(ActiveSheet.rows.count), I always get 1,048,576. I tried all sorts
of ways to delete blank rows (blank in Column A) --- see below --- but
I still always have 1,048,576 using ActiveSheet.rows.count.

Any ideas on why this occurs? Alan

Sub DeleteBlankRows()
Dim row As Long, i As Long, LastRow As Long, content As String
Dim WS As Worksheet
With Application
.Calculation = xlCalculationManual
.ScreenUpdating = False
For Each WS In ActiveWorkbook.Worksheets
LastRow = WS.Rows.Count
Debug.Print WS.Name & ": " & LastRow & " rows"
'Deletes the entire row within the selection if the ENTIRE row
contains no data.
'We turn off calculation and screenupdating to speed up the
macro.
For row = LastRow To LastRow - 5 '1 Step -1
content = Trim(WS.Cells(row, 1).Value)
If Len(content) = 0 Then
' EntireRow.Delete
'Debug.Print " Deleted row " & row
End If
Next row
Debug.Print " " & LastRow & " rows"
Next WS
.Calculation = xlCalculationAutomatic
.ScreenUpdating = True
End With
End Sub
Public Function GetLastRow(ByVal rngToCheck As Range) As Long

Dim rngLast As Range

Set rngLast = rngToCheck.Find(what:="*", searchorder:=xlByRows,
searchdirection:=xlPrevious)

If rngLast Is Nothing Then
GetLastRow = rngToCheck.row
Else
GetLastRow = rngLast.row
End If

End Function

Sub DeleteBlankRows1111()
Dim lngLastRow As Long
Dim rngToCheck As Range

Application.ScreenUpdating = False

With ActiveSheet
Debug.Print .Name & " has " & .Rows.Count & " rows"
'if the sheet is empty then exit...
If Application.WorksheetFunction.CountA(.Cells) 0 Then

'find the last row in the worksheet
lngLastRow = GetLastRow(.Cells)

Set rngToCheck = .Range(.Cells(1, 1), .Cells(lngLastRow,
1))

If rngToCheck.Count 1 Then
'if there are no blank cells then there will be an
error
On Error Resume Next

rngToCheck.SpecialCells(xlCellTypeBlanks).EntireRo w.Delete
On Error GoTo 0
Else
If VBA.IsEmpty(rngToCheck) Then
rngToCheck.EntireRow.Delete
End If
End If
Debug.Print .Rows.Count & " rows"
End With

Application.ScreenUpdating = True

End Sub

Sub DeleteBlankARows()
Dim r As Long
Debug.Print ActiveSheet.Rows.Count
For r = Cells(Rows.Count, 1).End(xlUp).row To 1 Step -1
If Cells(r, 1) = "" Then Rows(r).Delete
Next r
Debug.Print ActiveSheet.Rows.Count
End Sub


 
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 for up to 60000 rows of data gbpg Excel Programming 4 December 27th 09 08:37 PM
Deleting Blank Rows. GEM Excel Discussion (Misc queries) 3 April 15th 09 04:18 PM
Deleting blank rows which contain blank drop-down list boxes Al Excel Programming 3 February 18th 09 01:37 PM
Deleting Blank Rows Nigel Bennett Excel Programming 1 March 16th 05 12:31 AM
Deleting blank rows Alan M Excel Programming 3 January 26th 05 01:12 PM


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