PC Review


Reply
Thread Tools Rate Thread

delete rows in which the result of the formula is " "

 
 
marcia2026
Guest
Posts: n/a
 
      15th Jul 2008
This is my formula in each row in my table has an if/then statement to pick
up corresponding values from the same rows in other worksheets if the value
in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
want to be able to delete the rows with a "" value. I have tried to write a
Do/Until loop to look at each row in the table, but I cannot figure out how
to word the statement telling it what to do when it encounters the "" values.
 
Reply With Quote
 
 
 
 
RyanH
Guest
Posts: n/a
 
      15th Jul 2008
I would recommend using a For...Each Loop. The For...Each is more efficient
than a Do...Loop when you are working with objects. This procedure below
will scan down Col. A looking for values = "", if it finds one the entire row
is deleted.

Sub DeleteRows()

Dim LastRow As Long
Dim myRange As Range
Dim cell As Range

' finds last row in Col.A
LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row

' range of cells to test values
Set myRange = Sheets("Sheet1").Range(Cells(2, 1), Cells(LastRow, 1))

' loop thru each cell in myRange to find "" values
For Each cell In myRange
If cell.Value = "" Then
cell.EntireRow.Delete
End If
Next cell

End Sub

Hope this helps. If so please click "yes" below.
--
Cheers,
Ryan


"marcia2026" wrote:

> This is my formula in each row in my table has an if/then statement to pick
> up corresponding values from the same rows in other worksheets if the value
> in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
> want to be able to delete the rows with a "" value. I have tried to write a
> Do/Until loop to look at each row in the table, but I cannot figure out how
> to word the statement telling it what to do when it encounters the "" values.

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      15th Jul 2008
Sub remove_rows()
cl = "A"
n = Cells(Rows.Count, cl).End(xlUp).Row
For i = n To 1 Step -1
If Cells(i, cl).Value = "" Then
Cells(i, cl).EntireRow.Delete
End If
Next
End Sub

looks for blanks in column A. Adjust to suit your needs.
--
Gary''s Student - gsnu200795


"marcia2026" wrote:

> This is my formula in each row in my table has an if/then statement to pick
> up corresponding values from the same rows in other worksheets if the value
> in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
> want to be able to delete the rows with a "" value. I have tried to write a
> Do/Until loop to look at each row in the table, but I cannot figure out how
> to word the statement telling it what to do when it encounters the "" values.

 
Reply With Quote
 
marcia2026
Guest
Posts: n/a
 
      15th Jul 2008
Hi Ryan, I copied your code into my worksheet, when I tried to run it I
received the message "subscript out of range"

thanks,
marcia

"RyanH" wrote:

> I would recommend using a For...Each Loop. The For...Each is more efficient
> than a Do...Loop when you are working with objects. This procedure below
> will scan down Col. A looking for values = "", if it finds one the entire row
> is deleted.
>
> Sub DeleteRows()
>
> Dim LastRow As Long
> Dim myRange As Range
> Dim cell As Range
>
> ' finds last row in Col.A
> LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
>
> ' range of cells to test values
> Set myRange = Sheets("Sheet1").Range(Cells(2, 1), Cells(LastRow, 1))
>
> ' loop thru each cell in myRange to find "" values
> For Each cell In myRange
> If cell.Value = "" Then
> cell.EntireRow.Delete
> End If
> Next cell
>
> End Sub
>
> Hope this helps. If so please click "yes" below.
> --
> Cheers,
> Ryan
>
>
> "marcia2026" wrote:
>
> > This is my formula in each row in my table has an if/then statement to pick
> > up corresponding values from the same rows in other worksheets if the value
> > in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
> > want to be able to delete the rows with a "" value. I have tried to write a
> > Do/Until loop to look at each row in the table, but I cannot figure out how
> > to word the statement telling it what to do when it encounters the "" values.

 
Reply With Quote
 
marcia2026
Guest
Posts: n/a
 
      15th Jul 2008
worked. Thanks

"Gary''s Student" wrote:

> Sub remove_rows()
> cl = "A"
> n = Cells(Rows.Count, cl).End(xlUp).Row
> For i = n To 1 Step -1
> If Cells(i, cl).Value = "" Then
> Cells(i, cl).EntireRow.Delete
> End If
> Next
> End Sub
>
> looks for blanks in column A. Adjust to suit your needs.
> --
> Gary''s Student - gsnu200795
>
>
> "marcia2026" wrote:
>
> > This is my formula in each row in my table has an if/then statement to pick
> > up corresponding values from the same rows in other worksheets if the value
> > in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
> > want to be able to delete the rows with a "" value. I have tried to write a
> > Do/Until loop to look at each row in the table, but I cannot figure out how
> > to word the statement telling it what to do when it encounters the "" values.

 
Reply With Quote
 
marcia2026
Guest
Posts: n/a
 
      15th Jul 2008
Sorry. I spoke too soon. Actually, this one didn't work either.

"marcia2026" wrote:

> worked. Thanks
>
> "Gary''s Student" wrote:
>
> > Sub remove_rows()
> > cl = "A"
> > n = Cells(Rows.Count, cl).End(xlUp).Row
> > For i = n To 1 Step -1
> > If Cells(i, cl).Value = "" Then
> > Cells(i, cl).EntireRow.Delete
> > End If
> > Next
> > End Sub
> >
> > looks for blanks in column A. Adjust to suit your needs.
> > --
> > Gary''s Student - gsnu200795
> >
> >
> > "marcia2026" wrote:
> >
> > > This is my formula in each row in my table has an if/then statement to pick
> > > up corresponding values from the same rows in other worksheets if the value
> > > in the subsequent worksheet is greater than 0, otherwise leave blank. Now I
> > > want to be able to delete the rows with a "" value. I have tried to write a
> > > Do/Until loop to look at each row in the table, but I cannot figure out how
> > > to word the statement telling it what to do when it encounters the "" values.

 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      15th Jul 2008
ryan -
for-next or do-loop won't work in deleting rows moving from the top to
the bottom.......... if you are on row 19 & delete the entire row, row
20 moves up into row 19, but the macro goes to row 20. so you've
missed a row. that's why gary went from the bottom up to the top -
that way when you delete the row you don't miss one.

susan



On Jul 15, 12:50*pm, RyanH <Ry...@discussions.microsoft.com> wrote:
> I would recommend using a For...Each Loop. *The For...Each is more efficient
> than a Do...Loop when you are working with objects. *This procedure below
> will scan down Col. A looking for values = "", if it finds one the entire row
> is deleted.
>
> Sub DeleteRows()
>
> Dim LastRow As Long
> Dim myRange As Range
> Dim cell As Range
>
> * * ' finds last row in Col.A
> * * LastRow = Sheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
>
> * * ' range of cells to test values
> * * Set myRange = Sheets("Sheet1").Range(Cells(2, 1), Cells(LastRow, 1))
>
> * * ' loop thru each cell in myRange to find "" values
> * * For Each cell In myRange
> * * * * If cell.Value = "" Then
> * * * * * * cell.EntireRow.Delete
> * * * * End If
> * * Next cell
>
> End Sub
>
> Hope this helps. *If so please click "yes" below.
> --
> Cheers,
> Ryan
>
>
>
> "marcia2026" wrote:
> > This is my formula in each row in my table has an if/then statement to pick
> > up corresponding values from the same rows in other worksheets if the value
> > in the subsequent worksheet is greater than 0, otherwise leave blank. *Now I
> > want to be able to delete the rows with a "" value. *I have tried to write a
> > Do/Until loop to look at each row in the table, but I cannot figure outhow
> > to word the statement telling it what to do when it encounters the "" values.- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
Susan
Guest
Posts: n/a
 
      15th Jul 2008
this is the same (basically) as gary's, but the variables are
declared..........
===========================
Option Explicit

Sub step_backwards()

Dim myLastRow As Long
Dim r As Long
Dim c As Range

myLastRow = ActiveSheet.Cells(10000, 1).End(xlUp).Row

For r = myLastRow To 1 Step -1
Set c = ActiveSheet.Range("a" & r)
If c.Value = "" Then
c.EntireRow.Delete
End If
Next r

End Sub
=========================
again, it looks for blanks in column A.
hope it helps
susan



On Jul 15, 2:08*pm, marcia2026 <marcia2...@discussions.microsoft.com>
wrote:
> Sorry. *I spoke too soon. *Actually, this one didn't work either.
>
>
>
> "marcia2026" wrote:
> > worked. *Thanks

>
> > "Gary''s Student" wrote:

>
> > > Sub remove_rows()
> > > cl = "A"
> > > n = Cells(Rows.Count, cl).End(xlUp).Row
> > > For i = n To 1 Step -1
> > > * * If Cells(i, cl).Value = "" Then
> > > * * * * Cells(i, cl).EntireRow.Delete
> > > * * End If
> > > Next
> > > End Sub

>
> > > looks for blanks in column A. *Adjust to suit your needs.
> > > --
> > > Gary''s Student - gsnu200795

>
> > > "marcia2026" wrote:

>
> > > > This is my formula in each row in my table has an if/then statementto pick
> > > > up corresponding values from the same rows in other worksheets if the value
> > > > in the subsequent worksheet is greater than 0, otherwise leave blank. *Now I
> > > > want to be able to delete the rows with a "" value. *I have triedto write a
> > > > Do/Until loop to look at each row in the table, but I cannot figureout how
> > > > to word the statement telling it what to do when it encounters the "" values.- Hide quoted text -

>
> - Show quoted text -


 
Reply With Quote
 
ward376
Guest
Posts: n/a
 
      26th Jul 2008
Skip the loops altogether:

This looks in column a for mts and deletes the rows when found:
Sub RemoveMTCellRows()
On Error Resume Next

ActiveSheet.Columns(1).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
On Error GoTo 0
End Sub

Cliff Edwards
 
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
Formula Result is "V6", need Excel to use cell "V6", not the resul Erik Microsoft Excel Worksheet Functions 3 5th Sep 2008 03:10 PM
Mult formula cell displays "0", which formula created result? Reveal which formula causing true result Microsoft Excel Worksheet Functions 3 24th May 2008 04:16 PM
Is it possible to change the "result of a formula" to a "number? =?Utf-8?B?UmVuZWUgUi4=?= Microsoft Excel Misc 1 8th Feb 2005 02:36 PM
Is it possible to change the "result of a formula" to a "number? =?Utf-8?B?UmVuZWUgUi4=?= Microsoft Excel Misc 0 8th Feb 2005 02:27 PM
Formula to delete duplicate rows in "merged" worksheet Colin Bembridge Microsoft Excel Worksheet Functions 2 27th Aug 2003 03:01 PM


Features
 

Advertising
 

Newsgroups
 


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