LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default conditional format based on column statistics and loop over columns

Hello all,
I would like to have a macro to highlight outliers for each column. The outliers are the values which is not missing , but are out of limits.

The quartile ranges IQR is(use column D as example):
IQR=Q3-Q1=QUARTILE(D2:D44,3)-QUARTILE(D2:D44,1)
upper limit is Q3+IQR
lower limit is Q1+IQR



Here is the macro I recorded for using one test data(one column)

'Sub findoutlier()
''
'' findoutlier Macro
''
''
Range("A1:A43").Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND($A1 < ""."", OR($A1<(QUARTILE(A1:A43, 1)-1.5*(QUARTILE(A1:A43, 3)-QUARTILE(A1:A43, 1))), $A1(QUARTILE(A1:A43, 1)+1.5*(QUARTILE(A1:A43, 3)-QUARTILE(A1:A43, 1)))))"
Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
End Sub


I want to loop over 30 columns, and I added loops, but it does not work :(

Sub findoutlier()
'
' findoutlier Macro
'
'
Dim i As Long
Dim j As Long
Sheets("Sheet1").Select
For i = 1 To 30
For j = 1 To 44
' Range(Cells(2, i + 3), Cells(44, i + 3)).Select
Selection.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=AND(cells(j, i+3) < ""."", OR (cells(j, i+3)<(QUARTILE(range(cells(2, i+3), cells(44, i+3)), 1)-1.5*(QUARTILE(range(cells(2, i+3), cells(44, i+3)), 3)-QUARTILE(range(cells(2, i+3), cells(44, i+3)), 1))), (cells(j, i+3)(QUARTILE(range(cells(2, i+3), cells(44, i+3)), 1)+1.5*(QUARTILE(range(cells(2, i+3), cells(44, i+3)), 3)-QUARTILE(range(cells(2, i+3), cells(44, i+3)), 1)))))"
Selection.FormatConditions(Selection.FormatConditi ons.Count).SetFirstPriority
With Selection.FormatConditions(1).Interior
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False

Next j
Next i

End Sub

I am not sure if the error is cause by "(QUARTILE(range(cells(". Some similar test takes a long time to loop through all cells and I also would like suggestion on how to make this more efficient.

Any help would be much appreciated.

Haley

 
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
Conditional format based on a different column ArcticWolf Excel Worksheet Functions 2 January 23rd 09 10:15 AM
Conditional format row based on 1 column. FStuttgen Excel Discussion (Misc queries) 3 November 4th 08 07:36 PM
conditional format on column based on cell value kixy1 Excel Worksheet Functions 2 August 22nd 08 08:52 PM
How to conditional format columns in a range based on BlyChris Excel Worksheet Functions 5 July 25th 08 06:10 AM
Conditional Format a column based on another Karm Excel Discussion (Misc queries) 6 October 30th 06 11:39 AM


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