eric-apfel
New Member
- Joined
- Feb 22, 2013
- Messages
- 3
Hello Mr. Excel!
I want to start by saying a quick thank you! I love this site.
I have tried to find answers in previous posts but I haven't found anything to find material that applies directly here, yet.
I've been using VBA to new worksheets that compile information from a "Source" worksheet. For each row on "Source", the code creates a new sheet. The code also creates a "Menu" sheet with summary information and hyperlinks to each worksheet (making it relatively quick to jump around in a 500+ worksheet environment). On this "Menu" sheet, some of the summary data is formatted using conditional formatting, corresponding to certain values.
I am working with the following code to format a range of cells brace thyselves:
What you're thinking: Why are there some FormatCondition.Add's where Type = xlExpression and some where Type = xlCellValue?
Reason: At first I wanted just the one cell to change color based on the value inside it, but now I want multiple cells "B2:F2" to change to the same color depending on the value of "F2", and all subsequent rows.
Observations: This expression works:
But the expressions immediately preceeding it and following it don't.
My questions for you:
Very kind regards to any and all who are generous enough to help me!
Eric
I want to start by saying a quick thank you! I love this site.
I have tried to find answers in previous posts but I haven't found anything to find material that applies directly here, yet.
I've been using VBA to new worksheets that compile information from a "Source" worksheet. For each row on "Source", the code creates a new sheet. The code also creates a "Menu" sheet with summary information and hyperlinks to each worksheet (making it relatively quick to jump around in a 500+ worksheet environment). On this "Menu" sheet, some of the summary data is formatted using conditional formatting, corresponding to certain values.
I am working with the following code to format a range of cells brace thyselves:
Code:
Option Explicit
Public Sht_Name As Object
'I used Option Explicit to make sure that Sht_Name could be referenced by several parts of the code.
Dim Call_Range As Range
'... much further down
'The following is the beginning of the For Next Loop that creates the "NewSheets"
Set Call_Range = Sheets("Source").Range("A8:A507")
For Each Sht_Name In Call_Range
On Error Resume Next
If Sht_Name <> Empty Then
Call Create_NewSheet
'The following applies conditional formatting to the Status column in the Menu
With Sheets("Menu").Range("B" & Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1 & ":" & "F" & Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1)
.FormatConditions.Add Type:=xlExpression, Formula1:="=F" & (Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1) & "=" & "Not contacted"
.FormatConditions.Add Type:=xlExpression, Formula1:="=F" & (Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1) & "=" & "Voicemail"
.FormatConditions.Add Type:=xlExpression, Formula1:="=F" & (Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1) & "=" & "Message with secretary"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Marketing materials sent"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Pitch scheduled"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="In progress"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Rejected"
.FormatConditions.Add Type:=xlCellValue, Operator:=xlEqual, Formula1:="Closed"
.FormatConditions(1).StopIfTrue = False
.FormatConditions(1).Interior.Color = RGB(255, 255, 255)
.FormatConditions(2).StopIfTrue = False
.FormatConditions(2).Interior.Color = RGB(172, 185, 202)
.FormatConditions(3).StopIfTrue = False
.FormatConditions(3).Interior.Color = RGB(172, 185, 202)
.FormatConditions(4).StopIfTrue = False
.FormatConditions(4).Interior.Color = RGB(172, 185, 202)
.FormatConditions(5).StopIfTrue = False
.FormatConditions(5).Interior.Color = RGB(255, 255, 102)
.FormatConditions(6).StopIfTrue = False
.FormatConditions(6).Interior.Color = RGB(255, 192, 0)
.FormatConditions(7).StopIfTrue = False
.FormatConditions(7).Interior.Color = RGB(89, 89, 89)
.FormatConditions(8).StopIfTrue = False
.FormatConditions(8).Interior.Color = RGB(0, 176, 80)
End With
'... further down
End If
Next Sht_Name
What you're thinking: Why are there some FormatCondition.Add's where Type = xlExpression and some where Type = xlCellValue?
Reason: At first I wanted just the one cell to change color based on the value inside it, but now I want multiple cells "B2:F2" to change to the same color depending on the value of "F2", and all subsequent rows.
Observations: This expression works:
Code:
.FormatConditions.Add Type:=xlExpression, Formula1:="=F" & (Sheets("Source").Range(Sht_Name.Address(False, False)).Value + 1) & "=" & "Voicemail"
But the expressions immediately preceeding it and following it don't.
My questions for you:
- What's going on?
- How can I fix this?
- Is there a better way of doing this?
Very kind regards to any and all who are generous enough to help me!
Eric