Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Conditional Formatting

When doing conditional formatting and we wont to put it into VBA what does it
go under for the action to take place.

Do I create another Sub or Function and how does it activate.

Thanks
Noemi
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Conditional Formatting

this is some code from one of my modules, maybe it will give you and idea.
it does a sort operation first on the selected range and then colors odd
rows blue


With rng
..Sort Key1:=Range("header3").Offset(0, 1), Order1:=xlDescending,
Key2:=Range( _
"header3"), Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=1"

With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.FormatConditions(1).Interior.ColorIndex = 37
End With

--


Gary


"Noemi" wrote in message
...
When doing conditional formatting and we wont to put it into VBA what does
it
go under for the action to take place.

Do I create another Sub or Function and how does it activate.

Thanks
Noemi



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 74
Default Conditional Formatting

Hi Gary
what do you put the code under.

as we are not using a button how do you activate the code.

I tried putting under the selection change but it would not let me do
anything else.

Thanks
Noemi

"Gary Keramidas" wrote:

this is some code from one of my modules, maybe it will give you and idea.
it does a sort operation first on the selected range and then colors odd
rows blue


With rng
..Sort Key1:=Range("header3").Offset(0, 1), Order1:=xlDescending,
Key2:=Range( _
"header3"), Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=1"

With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.FormatConditions(1).Interior.ColorIndex = 37
End With

--


Gary


"Noemi" wrote in message
...
When doing conditional formatting and we wont to put it into VBA what does
it
go under for the action to take place.

Do I create another Sub or Function and how does it activate.

Thanks
Noemi




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Conditional Formatting

goes in with your code, in sheet code or a code module. just paste this in a
test workbook, either in a module or on the sheet's code page.

it will color odd rows between 1 and 20 in columns a through e blue

Option Explicit
Dim rng As Range

Sub color_rows()
Set rng = Range("a1:e20")
With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=1"

With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.FormatConditions(1).Interior.ColorIndex = 37
End With



End Sub

--


Gary


"Noemi" wrote in message
...
Hi Gary
what do you put the code under.

as we are not using a button how do you activate the code.

I tried putting under the selection change but it would not let me do
anything else.

Thanks
Noemi

"Gary Keramidas" wrote:

this is some code from one of my modules, maybe it will give you and
idea.
it does a sort operation first on the selected range and then colors odd
rows blue


With rng
..Sort Key1:=Range("header3").Offset(0, 1), Order1:=xlDescending,
Key2:=Range( _
"header3"), Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=1"

With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.FormatConditions(1).Interior.ColorIndex = 37
End With

--


Gary


"Noemi" wrote in message
...
When doing conditional formatting and we wont to put it into VBA what
does
it
go under for the action to take place.

Do I create another Sub or Function and how does it activate.

Thanks
Noemi






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default Conditional Formatting

and if you like, run this macro and it will show you the background colors
for the corresponding number

Option Explicit
Dim rng As Range
Dim i As Integer
Sub color_rows()
Application.ScreenUpdating = False
i = 1
For i = 1 To 56
Set rng = Rows(i)
With rng
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=ROW()"
.FormatConditions(1).Interior.ColorIndex = i
With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With

End With
Next
Application.ScreenUpdating = True
End Sub

--


Gary


"Noemi" wrote in message
...
Hi Gary
what do you put the code under.

as we are not using a button how do you activate the code.

I tried putting under the selection change but it would not let me do
anything else.

Thanks
Noemi

"Gary Keramidas" wrote:

this is some code from one of my modules, maybe it will give you and
idea.
it does a sort operation first on the selected range and then colors odd
rows blue


With rng
..Sort Key1:=Range("header3").Offset(0, 1), Order1:=xlDescending,
Key2:=Range( _
"header3"), Order2:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression, Formula1:= _
"=MOD(ROW(),2)=1"

With .FormatConditions(1).Borders
.LineStyle = xlContinuous
.Weight = xlThin
.ColorIndex = xlAutomatic
End With
.FormatConditions(1).Interior.ColorIndex = 37
End With

--


Gary


"Noemi" wrote in message
...
When doing conditional formatting and we wont to put it into VBA what
does
it
go under for the action to take place.

Do I create another Sub or Function and how does it activate.

Thanks
Noemi








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
How can I convert conditional formatting into explicit formatting? Patrick Harris Excel Discussion (Misc queries) 0 April 9th 09 12:00 AM
Formatting Conditional Formatting Icon Sets The Rook[_2_] Excel Discussion (Misc queries) 3 March 7th 09 08:48 PM
Protect Cell Formatting including Conditional Formatting Mick Jennings Excel Discussion (Misc queries) 5 November 13th 07 05:32 PM
conditional Formatting based on cell formatting Totom Excel Worksheet Functions 0 January 15th 07 04:35 PM
Conditional Formatting that will display conditional data BrainFart Excel Worksheet Functions 1 September 13th 05 05:45 PM


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