Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Applying conditinal formatting to sorted results

Hello,

I have a list of products that is being sorted by more than a few
columns. I am wanting to apply different cell colors to the rows
depending on the values in the sort. The data is a list of toys. most
of the sort columns are Y or N answers.

My data is structured with the following column headers.
Product group
item number
description
has metal
has plastic
has paint
has stickers
has synthetic fiber

So what we have is data that looks something like this.
001XXX, 001001, plastic truck - red, Y, Y, N, Y, N
001XXX, 001002, plastic truck - blue,Y, Y, N, Y, N
001XXX, 001011, metal truck - red, Y, Y, Y, Y, N
001XXX, 001012, metal truck - blue, Y, Y, Y, Y, N
002XXX, 002010, doll - blonde, N, Y, N, N, Y
002XXX, 002011, doll - red, N, Y, N, N, Y
002XXX, 002012, doll - brown, N, Y, N, N, Y
002XXX, 002110, doll - blonde, Y, Y, N, N, Y
002XXX, 002111, doll - red, Y, Y, N, N, Y
002XXX, 002112, doll - brown, Y, Y, N, N, Y
003XXX, 003003, ball - large, N, Y, N, N, N, N, Y
003XXX, 003013, ball - medium, N, Y, N, N, N
003XXX, 003023, ball - small, N, Y, N, N, N

All trucks have the same group because they are trucks, but I want to
change the color of the rows the metal trucks are on because they have
paint. A sort of the entire sheet will structure things so that the Y/
N columns are together but it is still easy to miss a difference in
the attributes. Since my real data has around 6000 rows I would like
to do this with a loop and automatically change the color of a row to
another color. So the code should go through the group 001XXX and
change the last two rows to blue. Then start to do the same thing to
the 002XXX group. The sheet is sorted left to right but ignores part
number and description.

Can anyone here help me with this please?
LWhite
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,290
Default Applying conditinal formatting to sorted results


Conditionally formatted colors will not sort with data.
And for what it's worth, neither will cell borders.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(download the free trial of Shade Data Rows)



"LWhite"

wrote in message
Hello,

I have a list of products that is being sorted by more than a few
columns. I am wanting to apply different cell colors to the rows
depending on the values in the sort. The data is a list of toys. most
of the sort columns are Y or N answers.

My data is structured with the following column headers.
Product group
item number
description
has metal
has plastic
has paint
has stickers
has synthetic fiber

So what we have is data that looks something like this.
001XXX, 001001, plastic truck - red, Y, Y, N, Y, N
001XXX, 001002, plastic truck - blue,Y, Y, N, Y, N
001XXX, 001011, metal truck - red, Y, Y, Y, Y, N
001XXX, 001012, metal truck - blue, Y, Y, Y, Y, N
002XXX, 002010, doll - blonde, N, Y, N, N, Y
002XXX, 002011, doll - red, N, Y, N, N, Y
002XXX, 002012, doll - brown, N, Y, N, N, Y
002XXX, 002110, doll - blonde, Y, Y, N, N, Y
002XXX, 002111, doll - red, Y, Y, N, N, Y
002XXX, 002112, doll - brown, Y, Y, N, N, Y
003XXX, 003003, ball - large, N, Y, N, N, N, N, Y
003XXX, 003013, ball - medium, N, Y, N, N, N
003XXX, 003023, ball - small, N, Y, N, N, N

All trucks have the same group because they are trucks, but I want to
change the color of the rows the metal trucks are on because they have
paint. A sort of the entire sheet will structure things so that the Y/
N columns are together but it is still easy to miss a difference in
the attributes. Since my real data has around 6000 rows I would like
to do this with a loop and automatically change the color of a row to
another color. So the code should go through the group 001XXX and
change the last two rows to blue. Then start to do the same thing to
the 002XXX group. The sheet is sorted left to right but ignores part
number and description.

Can anyone here help me with this please?
LWhite
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,836
Default Applying conditinal formatting to sorted results

I don't fully understand conditional formatting, but I think the color is
applied on top of the cell, instead of within the cell, so you can't really
measure what is in the cell. Nevertheless, you can 'evaluate' the
conditional formatting with the following code, and then you can sort based
on the results.

Function CountOfCF(InRange As Range, _
Optional Condition As Integer = -1) As Long
Dim Count As Long
Dim Rng As Range
Dim FCNum As Integer

For Each Rng In InRange.Cells
FCNum = ActiveCondition(Rng)
If FCNum 0 Then
If Condition = -1 Or Condition = FCNum Then
Count = Count + 1
End If
End If
Next Rng
CountOfCF = Count
End Function


Function ActiveCondition(Rng As Range) As Integer
Dim Ndx As Long
Dim FC As FormatCondition
Dim Temp As Variant
Dim Temp2 As Variant

If Rng.FormatConditions.Count = 0 Then
ActiveCondition = 0
Else
For Ndx = 1 To Rng.FormatConditions.Count
Set FC = Rng.FormatConditions(Ndx)
Select Case FC.Type
Case xlCellValue
Select Case FC.Operator
Case xlBetween
Temp = GetStrippedValue(FC.Formula1)
Temp2 = GetStrippedValue(FC.Formula2)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) = CDbl(FC.Formula1) And _
CDbl(Rng.Value) <= CDbl(FC.Formula2) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Rng.Value = Temp And _
Rng.Value <= Temp2 Then
ActiveCondition = Ndx
Exit Function
End If
End If

Case xlGreater
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Rng.Value Temp Then
ActiveCondition = Ndx
Exit Function
End If
End If

Case xlEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) = CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Temp = Rng.Value Then
ActiveCondition = Ndx
Exit Function
End If
End If


Case xlGreaterEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) = CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Rng.Value = Temp Then
ActiveCondition = Ndx
Exit Function
End If
End If


Case xlLess
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) < CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Rng.Value < Temp Then
ActiveCondition = Ndx
Exit Function
End If
End If

Case xlLessEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) <= CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Rng.Value <= Temp Then
ActiveCondition = Ndx
Exit Function
End If
End If


Case xlNotEqual
Temp = GetStrippedValue(FC.Formula1)
If IsNumeric(Temp) Then
If CDbl(Rng.Value) < CDbl(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Temp < Rng.Value Then
ActiveCondition = Ndx
Exit Function
End If
End If

Case xlNotBetween
Temp = GetStrippedValue(FC.Formula1)
Temp2 = GetStrippedValue(FC.Formula2)
If IsNumeric(Temp) Then
If Not (CDbl(Rng.Value) <= CDbl(FC.Formula1)) And _
(CDbl(Rng.Value) = CDbl(FC.Formula2)) Then
ActiveCondition = Ndx
Exit Function
End If
Else
If Not Rng.Value <= Temp And _
Rng.Value = Temp2 Then
ActiveCondition = Ndx
Exit Function
End If
End If

Case Else
Debug.Print "UNKNOWN OPERATOR"
End Select


Case xlExpression
If Application.Evaluate(FC.Formula1) Then
ActiveCondition = Ndx
Exit Function
End If

Case Else
Debug.Print "UNKNOWN TYPE"
End Select

Next Ndx

End If

ActiveCondition = 0



End Function



Function GetStrippedValue(CF As String) As String
Dim Temp As String
If InStr(1, CF, "=", vbTextCompare) Then
Temp = Mid(CF, 3, Len(CF) - 3)
If Left(Temp, 1) = "=" Then
Temp = Mid(Temp, 2)
End If
Else
Temp = CF
End If
GetStrippedValue = Temp
End Function

I forgot where I found this code, so if you have lots of questions you may
be out of luck. Just try it; it should work for you.

Call the function with this:
=ActiveCondition(A1)

Regards,
Ryan--

--
RyGuy


"Jim Cone" wrote:


Conditionally formatted colors will not sort with data.
And for what it's worth, neither will cell borders.
--
Jim Cone
San Francisco, USA
http://www.realezsites.com/bus/primitivesoftware
(download the free trial of Shade Data Rows)



"LWhite"

wrote in message
Hello,

I have a list of products that is being sorted by more than a few
columns. I am wanting to apply different cell colors to the rows
depending on the values in the sort. The data is a list of toys. most
of the sort columns are Y or N answers.

My data is structured with the following column headers.
Product group
item number
description
has metal
has plastic
has paint
has stickers
has synthetic fiber

So what we have is data that looks something like this.
001XXX, 001001, plastic truck - red, Y, Y, N, Y, N
001XXX, 001002, plastic truck - blue,Y, Y, N, Y, N
001XXX, 001011, metal truck - red, Y, Y, Y, Y, N
001XXX, 001012, metal truck - blue, Y, Y, Y, Y, N
002XXX, 002010, doll - blonde, N, Y, N, N, Y
002XXX, 002011, doll - red, N, Y, N, N, Y
002XXX, 002012, doll - brown, N, Y, N, N, Y
002XXX, 002110, doll - blonde, Y, Y, N, N, Y
002XXX, 002111, doll - red, Y, Y, N, N, Y
002XXX, 002112, doll - brown, Y, Y, N, N, Y
003XXX, 003003, ball - large, N, Y, N, N, N, N, Y
003XXX, 003013, ball - medium, N, Y, N, N, N
003XXX, 003023, ball - small, N, Y, N, N, N

All trucks have the same group because they are trucks, but I want to
change the color of the rows the metal trucks are on because they have
paint. A sort of the entire sheet will structure things so that the Y/
N columns are together but it is still easy to miss a difference in
the attributes. Since my real data has around 6000 rows I would like
to do this with a loop and automatically change the color of a row to
another color. So the code should go through the group 001XXX and
change the last two rows to blue. Then start to do the same thing to
the 002XXX group. The sheet is sorted left to right but ignores part
number and description.

Can anyone here help me with this please?
LWhite

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
Conditinal Formatting PA New Users to Excel 1 October 4th 08 01:58 AM
Conditinal Formatting Joe K. Excel Discussion (Misc queries) 0 October 22nd 07 02:51 AM
Conditinal Formatting Myriam Excel Programming 2 November 27th 06 09:11 PM
Conditinal formatting - AND function MariusSZ Excel Worksheet Functions 2 November 22nd 06 03:59 PM
Font size in conditinal formatting GDC Excel Discussion (Misc queries) 0 October 18th 05 06:38 PM


All times are GMT +1. The time now is 05:35 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"