Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default IF - THEN question

In my spreadsheet, col. A contains quantities, col. B contains prices. In
column D, I have formulas multiplying quantity times price. Column D cells
are also formatted as currency, and they display $0.00 when no quantity is
present.

I've named col. D as a range ("HideRows"). My goal is to have my code
search my named range, and for each cell containing $0.00, if the
corresponding quantity cell is empty, hide the row. If the quantity is
entered as zero, I don't want the row to be hidden. My code is below, but it
is not recognizing my conditions. What am I missing? Thanks for your help!

Sub HidePLRows()
Dim cell As Range
Application.ScreenUpdating = False
Range("HideRows").Select
For Each cell In Range("HideRows")
If ActiveCell.Value = "$0.00" And ActiveCell.Offset(0, -3).Value = ""
Then
Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
End If
Next
Range("A14").Select
Application.ScreenUpdating = True
End Sub

--
Steve C
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default IF - THEN question

The cell may be formatted as $0.00, but the value is 0.

And then, if you iterate through a range using an object called cell, you
should use cell, not activecell.

And then, because you are iterating through in a 'look-ahead' type of loop,
there is not need to slect anything.

Sub HidePLRows()
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("HideRows")
If cell.Value = 0 And cell.Offset(0, -3).Value = "" Then
cell.EntireRow.Hidden = True
End If
Next
Range("A14").Select
Application.ScreenUpdating = True
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Steve C" wrote in message
...
In my spreadsheet, col. A contains quantities, col. B contains prices. In
column D, I have formulas multiplying quantity times price. Column D

cells
are also formatted as currency, and they display $0.00 when no quantity is
present.

I've named col. D as a range ("HideRows"). My goal is to have my code
search my named range, and for each cell containing $0.00, if the
corresponding quantity cell is empty, hide the row. If the quantity is
entered as zero, I don't want the row to be hidden. My code is below, but

it
is not recognizing my conditions. What am I missing? Thanks for your

help!

Sub HidePLRows()
Dim cell As Range
Application.ScreenUpdating = False
Range("HideRows").Select
For Each cell In Range("HideRows")
If ActiveCell.Value = "$0.00" And ActiveCell.Offset(0, -3).Value = ""
Then
Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
End If
Next
Range("A14").Select
Application.ScreenUpdating = True
End Sub

--
Steve C



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default IF - THEN question

Just a quick guess, not tested. Perhaps you need to change:

If ActiveCell.Value = "$0.00"

to

If ActiveCell.Value = 0

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default IF - THEN question

Hi Steve C

I think "" and 0 are being treated as equals.

Try: If ActiveCell.Value = "$0.00" And IsEmpty(ActiveCell.Offset(0,
-3).Value)

Moreover, you can dispense with your ActiveCell refrences and
Selections because you've told Excel to look at Each cell

Try: If cell = "$0.00" And IsEmpty(cell.Offset(0, -3)) Then
cell.EntireRow.Hidden = True

There's no need to Select the next cell

Regards

Steve

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 119
Default IF - THEN question

Bob,

That's what I was looking for. Thanks a ton!
--
Steve C


"Bob Phillips" wrote:

The cell may be formatted as $0.00, but the value is 0.

And then, if you iterate through a range using an object called cell, you
should use cell, not activecell.

And then, because you are iterating through in a 'look-ahead' type of loop,
there is not need to slect anything.

Sub HidePLRows()
Dim cell As Range
Application.ScreenUpdating = False
For Each cell In Range("HideRows")
If cell.Value = 0 And cell.Offset(0, -3).Value = "" Then
cell.EntireRow.Hidden = True
End If
Next
Range("A14").Select
Application.ScreenUpdating = True
End Sub


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"Steve C" wrote in message
...
In my spreadsheet, col. A contains quantities, col. B contains prices. In
column D, I have formulas multiplying quantity times price. Column D

cells
are also formatted as currency, and they display $0.00 when no quantity is
present.

I've named col. D as a range ("HideRows"). My goal is to have my code
search my named range, and for each cell containing $0.00, if the
corresponding quantity cell is empty, hide the row. If the quantity is
entered as zero, I don't want the row to be hidden. My code is below, but

it
is not recognizing my conditions. What am I missing? Thanks for your

help!

Sub HidePLRows()
Dim cell As Range
Application.ScreenUpdating = False
Range("HideRows").Select
For Each cell In Range("HideRows")
If ActiveCell.Value = "$0.00" And ActiveCell.Offset(0, -3).Value = ""
Then
Selection.EntireRow.Hidden = True
Else
ActiveCell.Offset(1, 0).Select
End If
Next
Range("A14").Select
Application.ScreenUpdating = True
End Sub

--
Steve C




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
Newbie Question - Subtraction Formula Question [email protected] Excel Discussion (Misc queries) 3 May 5th 06 05:50 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good davegb Excel Programming 1 May 6th 05 06:35 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 27th 05 07:46 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 23 April 23rd 05 09:26 PM
Good morning or good evening depending upon your location. I want to ask you the most important question of your life. Your joy or sorrow for all eternity depends upon your answer. The question is: Are you saved? It is not a question of how good you [email protected] Excel Programming 0 April 22nd 05 03:30 PM


All times are GMT +1. The time now is 11:23 AM.

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"