Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default excluding a value in a max determination

Hi

I want to determine a max value in a range: =MAX(A1:A3

But if one of the cells has this format

With Selection.Interio
.ColorIndex =
.Pattern = xlLightU
.PatternColorIndex = 2
End Wit

I want to exclude it from the max value determination. Can anybody help me out with a piece of code that returns the correct max value

Thank yo
Schwartz
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 78
Default excluding a value in a max determination

not elegant but...

first = True
For Each c In myRange
With c.Interior
If .ColorIndex < 2 Or .Pattern < xlLightUp Or _
.PatterColorIndex < 22 Then
If first Then
max = c.Value
first = False
ElseIf c.Value max Then
max = c.Value
End If
End If
End With
Next c
MsgBox "Max = " & max


Kevin Beckham

-----Original Message-----
Hi

I want to determine a max value in a range: =MAX(A1:A3)

But if one of the cells has this format:

With Selection.Interior
.ColorIndex = 2
.Pattern = xlLightUp
.PatternColorIndex = 22
End With

I want to exclude it from the max value determination.

Can anybody help me out with a piece of code that returns
the correct max value?

Thank you
Schwartz
.

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10
Default excluding a value in a max determination

Hey, it works for me - and there is no points for style..

Thank you agai
Schwartz
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default excluding a value in a max determination

I turned this into a UDF (just for the hell of it), to give flexibility, in
case Dr Schwartz has many such tests (sic!).

Function OddMax(rng As Range, _
Optional ColorIndex As Long = -1, _
Optional Pattern As Long = -1, _
Optional PatternColorIndex As Long = -1) As Range
Dim c As Range
Dim first As Boolean
Dim oRng As Range
first = True
For Each c In rng
With c.Interior
If ((ColorIndex = -1 Or .ColorIndex < ColorIndex) And _
(Pattern = -1 Or .Pattern < Pattern) And _
(PatternColorIndex = -1 Or .PatternColorIndex <
PatternColorIndex)) Then
If first Then
Set oRng = c
first = False
Else
Set oRng = Union(oRng, c)
End If
End If
End With
Next c
Set OddMax = oRng

End Function

Use like so

=MAX(oddmax(I1:I3,6)) ' justs excludes a colour

=MAX(oddmax(I1:I3,6,17)) ' excludes a colour or a pattern

=MAX(oddmax(I1:I3,6,17,7)) ' all 3

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Kevin Beckham" wrote in message
...
not elegant but...

first = True
For Each c In myRange
With c.Interior
If .ColorIndex < 2 Or .Pattern < xlLightUp Or _
.PatterColorIndex < 22 Then
If first Then
max = c.Value
first = False
ElseIf c.Value max Then
max = c.Value
End If
End If
End With
Next c
MsgBox "Max = " & max


Kevin Beckham

-----Original Message-----
Hi

I want to determine a max value in a range: =MAX(A1:A3)

But if one of the cells has this format:

With Selection.Interior
.ColorIndex = 2
.Pattern = xlLightUp
.PatternColorIndex = 22
End With

I want to exclude it from the max value determination.

Can anybody help me out with a piece of code that returns
the correct max value?

Thank you
Schwartz
.



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
coefficient of determination Jene Excel Worksheet Functions 2 August 27th 09 02:39 AM
Pick value off sheet list for VBA code determination Bill (Unique as my name) Excel Discussion (Misc queries) 1 September 21st 07 06:52 PM
Date determination and sums UnderCoverGuy Excel Worksheet Functions 0 October 31st 06 08:16 PM
Earned Value Determination Paul Excel Discussion (Misc queries) 0 March 25th 05 09:27 AM
Average determination Debra Excel Worksheet Functions 4 November 1st 04 01:22 PM


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

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"