PC Review


Reply
Thread Tools Rate Thread

delete rows in a given range

 
 
Wen
Guest
Posts: n/a
 
      27th Nov 2009
Anyone has a good sub to delete from a given range any row with blank index
cell?
For example, I have a table range with column A titled "Name" as index
column. I need a sub that deletes any row where column A is blank, but say,
column C has non-blank value. it is not the same as deleting all blank rows
in a range.
TIA.
Wen

 
Reply With Quote
 
 
 
 
fisch4bill
Guest
Posts: n/a
 
      30th Nov 2009
In order for this code to work for me, I had to change the line:

lngLastRow = wks.Cells(Rows.Count, "A").End(xlUp).End

to:

lngLastRow = wks.Cells(Rows.Count, "A").End(xlUp).Row

Using the original line resulted in Run-time error '450': "Wrong number of
arguments or invalid property assignment"

Otherwise, once I changed the reference to the value I was testing for it
worked flawlessly and the logic was just what I needed.

Thanks Ryan.

"Ryan H" wrote:

> Just adjust the worksheet name, first row, and last row variables and it
> should work for you. If you don't want the entire row deleted let me know.
> If this helps click "YES" below.
>
> Sub DeleteRows()
>
> Dim wks As Worksheet
> Dim lngFirstRow As Long
> Dim lngLastRow As Long
>
> Set wks = Sheets("Sheet1")
> lngFirstRow = 2
> lngLastRow = wks.Cells(Rows.Count, "A").End(xlUp).End
>
> ' clears empty rows from sheet
> With wks
> For i = lngLastRow To lngFirstRow Step -1
> If Trim(.Cells(i, "A")) = "" Then
> .Cells(i, "A").EntireRow.Delete Shift:=xlUp
> End If
> Next i
> End With
> End Sub
> --
> Cheers,
> Ryan
>
>
> "Wen" wrote:
>
> > Anyone has a good sub to delete from a given range any row with blank index
> > cell?
> > For example, I have a table range with column A titled "Name" as index
> > column. I need a sub that deletes any row where column A is blank, but say,
> > column C has non-blank value. it is not the same as deleting all blank rows
> > in a range.
> > TIA.
> > Wen
> >
> > .
> >

 
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
Re: delete rows in a given range Rick Rothstein Microsoft Excel Programming 0 27th Nov 2009 05:06 PM
RE: delete rows in a given range Ryan H Microsoft Excel Programming 0 27th Nov 2009 04:20 PM
Delete rows if not as range Kashyap Microsoft Excel Programming 3 29th Mar 2009 11:11 AM
Delete a range of rows Lotto Microsoft Excel Discussion 2 27th Mar 2009 06:48 PM
Delete a range of rows Lotto Microsoft Excel Discussion 1 27th Mar 2009 06:40 PM


Features
 

Advertising
 

Newsgroups
 


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