Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default conditional format macro formula

Hi I am learning to use macro's and am having trouble determining the formula
to put in a macro. ( I only have two variables and I know that conditional
formatting can do this but I am trying to learn what to do.) My variables
are that the cell would contain either more than 4 digits or that it would
contain the word "workbook".

How do I write the formula to put into this formatting macro?

Thanks.

Sub ColorRowBasedOnCellValue()
'David McRitchie, 2001-01-17 programming -- Color row based on value
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
For Each cell In Intersect(Selection, ActiveCell.EntireColumn, _
ActiveSheet.UsedRange)
Select Case cell.Value
Case Is = "workbook"
cell.EntireRow.Interior.ColorIndex = 20
Case Is = 40
cell.EntireRow.Interior.ColorIndex = 37
End Select
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default conditional format macro formula

If it will only contain 2 things then

Sub ColorRowBasedOnCellValue()
'David McRitchie, 2001-01-17 programming -- Color row based on value
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
For Each cell In Intersect(Selection, ActiveCell.EntireColumn, _
ActiveSheet.UsedRange)
if len(trim(cell.Value)) = 0 then
' nothing
cell.Interior.ColorIndex = xlNone
elseif len(cell.Value) = 4 then
cell.Interior.ColorIndex = 37
elseif instr(1,cell.Value,"workbook",vbtextcompare) then
cell.interior.colorIndex = 20
else
' shouldn't get here but if you do make it red
cell.Interior.ColorIndex = 3
end if
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub

Modify to suit.

--
Regards,
Tom Ogilvy

"Todd" wrote:

Hi I am learning to use macro's and am having trouble determining the formula
to put in a macro. ( I only have two variables and I know that conditional
formatting can do this but I am trying to learn what to do.) My variables
are that the cell would contain either more than 4 digits or that it would
contain the word "workbook".

How do I write the formula to put into this formatting macro?

Thanks.

Sub ColorRowBasedOnCellValue()
'David McRitchie, 2001-01-17 programming -- Color row based on value
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim cell As Range
For Each cell In Intersect(Selection, ActiveCell.EntireColumn, _
ActiveSheet.UsedRange)
Select Case cell.Value
Case Is = "workbook"
cell.EntireRow.Interior.ColorIndex = 20
Case Is = 40
cell.EntireRow.Interior.ColorIndex = 37
End Select
Next cell
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
End Sub

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
Worksheet macro conditional format question Dingy101 Excel Discussion (Misc queries) 3 June 8th 09 07:54 PM
Conditional Format as a MACRO Gunjani Excel Worksheet Functions 3 March 29th 06 05:22 PM
conditional format macro not working - almost there Naz Excel Programming 3 December 9th 05 09:53 PM
Multiple conditional on conditional format formula Frank Kabel Excel Programming 1 July 27th 04 06:24 PM
Multiple conditional on conditional format formula Bob Phillips[_7_] Excel Programming 0 July 27th 04 05:30 PM


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