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

This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 735
Default Conditional Formatting Issue

I tried it in xl2007 using code below and it worked fine!

Sub ConditionalFormatting()
Dim lngdeptlastrow As Long
With ActiveSheet
lngdeptlastrow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngdeptlastrow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, Operator:=xlLess,
Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngdeptlastrow)
.FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With
End With
End Sub

--

Regards,
Nigel




"RyanH" wrote in message
...
This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an
error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Conditional Formatting Issue

There are a few problems with the code don't know why you didn't get more
errors

1) You have a period in front of a number of items without a WIT statment.
I added Activesheet
2) You can't apply formatcondition to a range of cells. I added a FOR loop
to handle the situation.
3) Your color index statement is wrong. Not sure what you want to do.
Changed it to just color the cell.


Sub ConditionalFormatting()
With ActiveSheet
lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green

For Each cell In .Range("A5:O" & lngDeptLastRow)
cell.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0"
cell.Interior.ColorIndex = 35
Next cell
End With
End Sub

"RyanH" wrote:

This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Conditional Formatting Issue

Thanks for the replys.

Nigel,
I got this code to work in 2007 also, but at work we have 2003 and it
doesn't seem to work. I tried using the 2003 recorder and it doesn't want to
work right, so I guess it is a 2003 issue.

Joel,
Sorry for the confusion on the code. You are right, this is a piece of the
entire procedure and I failed to mention the With ActiveSheet statement,
sorry about that. If I can't apply format conditions to a Range then why is
the part where I want to highlight a range of cells red it works?

My basic goal is this. In Col.L I have dates and if the dates are less than
todays date change the color background to red. Then, I want to change the
background color to a light green for everyother row for easy reading. For
some reason it worked on the macro recorder but not in my code.
--
Cheers,
Ryan


"Joel" wrote:

There are a few problems with the code don't know why you didn't get more
errors

1) You have a period in front of a number of items without a WIT statment.
I added Activesheet
2) You can't apply formatcondition to a range of cells. I added a FOR loop
to handle the situation.
3) Your color index statement is wrong. Not sure what you want to do.
Changed it to just color the cell.


Sub ConditionalFormatting()
With ActiveSheet
lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green

For Each cell In .Range("A5:O" & lngDeptLastRow)
cell.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0"
cell.Interior.ColorIndex = 35
Next cell
End With
End Sub

"RyanH" wrote:

This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan

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

The VBA help is the same as your code. don't know why it doesn't work. I
also modified you code below to get the colorindex into the conditional
formating. I need another WITH

For Each cell In .Range("A5:O" & lngDeptLastRow)
With cell.FormatConditions.Add(Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0")
.Interior.ColorIndex = 35
End With
Next cell


"RyanH" wrote:

Thanks for the replys.

Nigel,
I got this code to work in 2007 also, but at work we have 2003 and it
doesn't seem to work. I tried using the 2003 recorder and it doesn't want to
work right, so I guess it is a 2003 issue.

Joel,
Sorry for the confusion on the code. You are right, this is a piece of the
entire procedure and I failed to mention the With ActiveSheet statement,
sorry about that. If I can't apply format conditions to a Range then why is
the part where I want to highlight a range of cells red it works?

My basic goal is this. In Col.L I have dates and if the dates are less than
todays date change the color background to red. Then, I want to change the
background color to a light green for everyother row for easy reading. For
some reason it worked on the macro recorder but not in my code.
--
Cheers,
Ryan


"Joel" wrote:

There are a few problems with the code don't know why you didn't get more
errors

1) You have a period in front of a number of items without a WIT statment.
I added Activesheet
2) You can't apply formatcondition to a range of cells. I added a FOR loop
to handle the situation.
3) Your color index statement is wrong. Not sure what you want to do.
Changed it to just color the cell.


Sub ConditionalFormatting()
With ActiveSheet
lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green

For Each cell In .Range("A5:O" & lngDeptLastRow)
cell.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0"
cell.Interior.ColorIndex = 35
Next cell
End With
End Sub

"RyanH" wrote:

This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Conditional Formatting Issue

I'll just do a Loop for the Date Column. Here is what I did. This works
great! Thanks for your help!

If lngFinalDate < 5 Then
' delete all data from dept
.Rows("5:" & lngLastRow + 2).Delete Shift:=xlUp
Else
' delete all non active items from dept
.Rows(lngFinalDate + 1 & ":" & lngLastRow + 2).Delete
Shift:=xlUp

' find last row of updated schedule
lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(1).Interior.ColorIndex = 35
End With

' highlight late dates red
lngRowCounter = 5
Do Until .Cells(lngRowCounter, "L") = Date Or
IsEmpty(.Cells(lngRowCounter, "L"))
With .Cells(lngRowCounter, "L")
.FormatConditions.Delete
.Interior.ColorIndex = 3
End With
lngRowCounter = lngRowCounter + 1
Loop
End If
--
Cheers,
Ryan


"Joel" wrote:

The VBA help is the same as your code. don't know why it doesn't work. I
also modified you code below to get the colorindex into the conditional
formating. I need another WITH

For Each cell In .Range("A5:O" & lngDeptLastRow)
With cell.FormatConditions.Add(Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0")
.Interior.ColorIndex = 35
End With
Next cell


"RyanH" wrote:

Thanks for the replys.

Nigel,
I got this code to work in 2007 also, but at work we have 2003 and it
doesn't seem to work. I tried using the 2003 recorder and it doesn't want to
work right, so I guess it is a 2003 issue.

Joel,
Sorry for the confusion on the code. You are right, this is a piece of the
entire procedure and I failed to mention the With ActiveSheet statement,
sorry about that. If I can't apply format conditions to a Range then why is
the part where I want to highlight a range of cells red it works?

My basic goal is this. In Col.L I have dates and if the dates are less than
todays date change the color background to red. Then, I want to change the
background color to a light green for everyother row for easy reading. For
some reason it worked on the macro recorder but not in my code.
--
Cheers,
Ryan


"Joel" wrote:

There are a few problems with the code don't know why you didn't get more
errors

1) You have a period in front of a number of items without a WIT statment.
I added Activesheet
2) You can't apply formatcondition to a range of cells. I added a FOR loop
to handle the situation.
3) Your color index statement is wrong. Not sure what you want to do.
Changed it to just color the cell.


Sub ConditionalFormatting()
With ActiveSheet
lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue, _
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green

For Each cell In .Range("A5:O" & lngDeptLastRow)
cell.FormatConditions.Add Type:=xlExpression, _
Formula1:="=MOD(ROW(),2)=0"
cell.Interior.ColorIndex = 35
Next cell
End With
End Sub

"RyanH" wrote:

This code is giving me fits and I can't see what the problem is. It is
probably obvious, but I'm so fustrated I can't see it. I am getting an error
below can someone tell me why? I am wanting to highlight every other row.
ERROR: Application Defined or Object Error

Sub ConditionalFormatting()

lngDeptLastRow = .Cells(Rows.Count, "A").End(xlUp).Row
' highlight late dates red
With .Range("L5:L" & lngDeptLastRow)
.FormatConditions.Delete
.FormatConditions.Add Type:=xlCellValue,
Operator:=xlLess, Formula1:="=TODAY()"
.FormatConditions(1).Interior.ColorIndex = 3
End With

' highlight everyother row light green
With .Range("A5:O" & lngDeptLastRow)
ERROR .FormatConditions.Add Type:=xlExpression,
Formula1:="=MOD(ROW(),2)=0"
.FormatConditions(2).Interior.ColorIndex = 35
End With

End Sub
--
Cheers,
Ryan

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
Issue with conditional formatting The Rook[_2_] Excel Discussion (Misc queries) 2 June 2nd 10 05:36 PM
Conditional Formatting Issue debra49424 Excel Discussion (Misc queries) 4 February 19th 09 07:10 PM
Conditional Formatting Issue Robert Excel Discussion (Misc queries) 8 September 1st 08 11:05 PM
Conditional Formatting Issue afsoares Excel Discussion (Misc queries) 3 June 30th 06 01:36 PM
conditional formatting issue QUESTION-MARK Excel Worksheet Functions 3 April 20th 06 01:04 AM


All times are GMT +1. The time now is 09:15 AM.

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"