PC Review


Reply
Thread Tools Rate Thread

Delete Row If Blank or Zero

 
 
Connie
Guest
Posts: n/a
 
      11th Oct 2006
I am using the following code to delete blank or zero rows on a sheet.
If I wanted to use only columns C through the end column to determine
whether the row is blank or zero, how would I do that? In other words,
I would like to modify the following to perform the counting or summing
beginning with row C rather than all the columns in the row:

If Application.CountA(sh.Rows(i)) = 0 Then
sh.Rows(i).Delete
ElseIf Application.Sum(sh.Rows(i)) = 0 Then
sh.Rows(i).Delete
End If

Any help would be appreciated. Thanks! Connie
***************************************************************************************************

Private Sub CreateUploadFile_Click()
Dim sh As Worksheet
Set sh = Worksheets("Upload Data")
Set rng = GetRealLastCell(sh)
'delete blank rows in upload file
For i = rng.Row To 2 Step -1
If Application.CountA(sh.Rows(i)) = 0 Then
sh.Rows(i).Delete
ElseIf Application.Sum(sh.Rows(i)) = 0 Then
sh.Rows(i).Delete
End If
Next
End Sub

Function GetRealLastCell(sh As Worksheet) As Range
Dim RealLastRow As Long
Dim RealLastColumn As Long
On Error Resume Next
RealLastRow = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
RealLastColumn = _
sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
xlPrevious).Column
Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
End Function

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      11th Oct 2006
Using the amended GetLastRealCell I gave in the last post

Private Sub CreateUploadFile_Click()
Dim sh As Worksheet
Dim iLastRow As Long
Dim iLastCol As Long
Set sh = Worksheets("Upload Data")
Set rng = GetRealLastCell(sh, iLastRow, iLastCol)
'delete blank rows in upload file
For i = rng.Row To 2 Step -1
If Application.CountA(sh.Range(sh.Cells(i, "C"), sh.Cells(i,
iLastCol))) = 0 Then
sh.Rows(i).Delete
ElseIf Application.Sum(sh.Range(sh.Cells(i, "C"), sh.Cells(i,
"IV"))) = 0 Then
sh.Rows(i).Delete
End If
Next
End Sub



--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Connie" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I am using the following code to delete blank or zero rows on a sheet.
> If I wanted to use only columns C through the end column to determine
> whether the row is blank or zero, how would I do that? In other words,
> I would like to modify the following to perform the counting or summing
> beginning with row C rather than all the columns in the row:
>
> If Application.CountA(sh.Rows(i)) = 0 Then
> sh.Rows(i).Delete
> ElseIf Application.Sum(sh.Rows(i)) = 0 Then
> sh.Rows(i).Delete
> End If
>
> Any help would be appreciated. Thanks! Connie
>

****************************************************************************
***********************
>
> Private Sub CreateUploadFile_Click()
> Dim sh As Worksheet
> Set sh = Worksheets("Upload Data")
> Set rng = GetRealLastCell(sh)
> 'delete blank rows in upload file
> For i = rng.Row To 2 Step -1
> If Application.CountA(sh.Rows(i)) = 0 Then
> sh.Rows(i).Delete
> ElseIf Application.Sum(sh.Rows(i)) = 0 Then
> sh.Rows(i).Delete
> End If
> Next
> End Sub
>
> Function GetRealLastCell(sh As Worksheet) As Range
> Dim RealLastRow As Long
> Dim RealLastColumn As Long
> On Error Resume Next
> RealLastRow = _
> sh.Cells.Find("*", sh.Range("A1"), , , xlByRows, xlPrevious).Row
> RealLastColumn = _
> sh.Cells.Find("*", sh.Range("A1"), , , xlByColumns,
> xlPrevious).Column
> Set GetRealLastCell = sh.Cells(RealLastRow, RealLastColumn)
> End Function
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Rows if any cell in Column H is blank but do not Delete Fir =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 28th Sep 2007 05:20 PM
Templete with blank pages - need to delete blank - how? =?Utf-8?B?ZnJ1c3RyYXRlZCB3aXRoIHRlbXBsYXRl?= Microsoft Access 3 21st Apr 2007 04:03 AM
Delete blank row only if 2 consecutive blank rows =?Utf-8?B?QW15?= Microsoft Excel Programming 2 21st Oct 2004 05:24 PM
Delete if blank... CPower Microsoft Excel Programming 3 11th Aug 2004 12:21 AM
Re: Help! I have 14 pages in a worksheet, pages 8-14 are blank and print that way. How can I delete only the blank pages? I tried delete worksheet and it deleted the whole thing. Frank Kabel Microsoft Excel New Users 1 28th Apr 2004 09:20 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:07 PM.