LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 227
Default Passing formula value to variable, hide rows

Hi Punsterr

Sub test()
'Assuming columns to be tested are D, G and J
Application.ScreenUpdating = False
Dim r As Range, c As Range, rr As Range
Set rr = Nothing
With ActiveSheet
Set r = .Range(.Range("D1"), .Range("D" & Rows.Count).End(xlUp))
r.EntireRow.Hidden = False
For Each c In r
If c = 0 And c.Offset(0, 3) = 0 And c.Offset(0, 6) = 0 Then
If rr Is Nothing Then
Set rr = c
Else
Set rr = Union(rr, c)
End If
End If
Next c
If Not rr Is Nothing Then rr.EntireRow.Hidden = True
End With
Application.ScreenUpdating = True
End Sub


--

Regards

William

XL2003




"Punsterr" wrote in message
oups.com...
I'm creating a macro that will check each row to determine the values
of three separate columns. If any of those three values are something
other than zero, then the macro will not Hide the row. Otherwise, if
all three values are zero, then the macro will hide the row.

The catch to this one is that 1) the cells we're checking are
formula-driven, and 2) the cell values that we're testing are typically
displayed in percentage terms. I'm having difficulty getting the value
to pass through the testing subroutine. I'm not sure if I should be
trying to convert the formula value to text first, and then test it, or
if there's a better way.

Here is a sample of a couple of different ways I've tried this:

----------------------
First Attempt


Dim TestRows As Integer
Dim count As Integer

For TestRows = 18 To 25
count = 0
If cells(testrows, 3).value < 0 then count = count +1
If cells(testrows, 7).value < 0 then count = count +1
If cells(testrows, 11).value < 0 then count = count +1

if count 0 Then
Cells(TestRows, 3).EntireRow.Hidden = False
Else
Cells(TestRows, 3).EntireRow.Hidden = True
End If

Next TestRows

--------------------------------

Second Attempt

Dim TestRows As Integer
Dim CellValue3 As String
Dim CellValue7 As String
Dim CellValue11 As String

' Check and store amounts shown in rows 18 - 25 in columns 3,
7, and 11

For TestRows = 18 To 25
CellValue3 = Cells(TestRows, 3).Text
CellValue7 = Cells(TestRows, 7).Text
CellValue11 = Cells(TestRows, 11).Text

' Print message boxes to show values for troubleshooting
MsgBox ("row " & TestRows & "column 3 = " & CellValue3)
MsgBox ("row " & TestRows & "column 7 = " & CellValue7)
MsgBox ("row " & TestRows & "column 11 = " & CellValue11)
If CellValue3 < "0" And CellValue3 < "0%" And CellValue7
< "0"_
And CellValue7 < "0%" And CellValue11 < "0" And
CellValue3 < "0%" Then
Cells(TestRows, 3).EntireRow.Hidden = False
Else
Cells(TestRows, 3).EntireRow.Hidden = True
End If

Next TestRows

------------------------------

Neither of these attempts have worked. I'm sure my problem is
somewhere in my variable types, but I'm not sure about what's wrong or
how to make it all work, and work efficiently. I'd appreciate any
suggestions you have!



 
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
How to hide rows in an Excel worksheet based on a variable Dave Osborn Excel Discussion (Misc queries) 2 July 21st 09 10:11 PM
multiplying rows and passing formula throughout the col range Sistereinstein Excel Discussion (Misc queries) 3 December 31st 07 08:31 PM
Passing Variable to LINEST RW Excel Worksheet Functions 5 May 24th 05 07:00 PM
Passing variable to VarType of other Variable ExcelMonkey[_190_] Excel Programming 3 February 22nd 05 01:38 PM
Passing variable from one sub to another Medemper Excel Programming 0 February 26th 04 10:23 PM


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