Eloise T
Active Member
The following picture says it best:
I created a new spreadsheet with only 3 colored cells and went through the Developer tab --> Record Macro to get the "code" for setting the colors to gradient-shading, etc., and of course it won't allow me to plug it in directly to the "real" workbook without a few changes.
The first VBA code (see below) is my feeble attempt to "fit" the Recorded Macro in to a partial of the "real" spreadsheet where there are only 4 lines that seem to be a problem. This is before knowing whether or not it will work once the gradient-shading code has been incorporated in, but I'm believing the best.
The 2nd VBA code is solely the VBA code coughed up by the Record Macro. I have also uploaded the file which I created to get the Recorded Macro.
I can also upload the entire sanitized version of the "real" spreadsheet before my attempt to incorporate the Recorded Macro in if anyone thinks that would help, but I think everything needed to solve this conundrum is currently included.
THANK YOU for your help.
P.S. Why is it sometimes, probably 50% of the time I try to Record Macro, it doesn't work and I only get:
???
I created a new spreadsheet with only 3 colored cells and went through the Developer tab --> Record Macro to get the "code" for setting the colors to gradient-shading, etc., and of course it won't allow me to plug it in directly to the "real" workbook without a few changes.
The first VBA code (see below) is my feeble attempt to "fit" the Recorded Macro in to a partial of the "real" spreadsheet where there are only 4 lines that seem to be a problem. This is before knowing whether or not it will work once the gradient-shading code has been incorporated in, but I'm believing the best.
The 2nd VBA code is solely the VBA code coughed up by the Record Macro. I have also uploaded the file which I created to get the Recorded Macro.
I can also upload the entire sanitized version of the "real" spreadsheet before my attempt to incorporate the Recorded Macro in if anyone thinks that would help, but I think everything needed to solve this conundrum is currently included.
THANK YOU for your help.
Code:
Sub Conditional_Format_Reset()
Dim ws As Worksheet
For Each ws In ThisWorkbook.Worksheets
If ws.Cells(Rows.Count, 3).End(xlUp).Row > 2 Then
lLastRow = ws.Cells(Rows.Count, 3).End(xlUp).Row - 2
With ws.Range("C3:C" & lLastRow) 'Intended Range =$C$3:$C$5003
' Using a "Formulas" tab --> Name Manager, find all the 70 models and color them as designated below.
.FormatConditions.Add Type:=xlExpression, Formula1:="=OR(ISNUMBER(SEARCH(SearchFor70,$C3)))"
.FormatConditions(.FormatConditions.Count).Font.ColorIndex = 1 'Black
.FormatConditions(.FormatConditions.Count).Interior.ColorIndex = 3 'Red
.FormatConditions(.FormatConditions.Count).SetFirstPriority
.FormatConditions(.FormatConditions.Count).Font.Bold = True
.FormatConditions(.FormatConditions.Count).Font.Italic = False
.FormatConditions(.FormatConditions.Count).Font.TintAndShade = 0
' End With
' .FormatConditions(.FormatConditions.Count).Interior
.FormatConditions(.FormatConditions.Count).Interior.Pattern = xlPatternLinearGradient
.FormatConditions(.FormatConditions.Count).Interior.Gradient.Degree = 0
.FormatConditions(.FormatConditions.Count).Interior.Gradient.ColorStops.Clear
' End With
.FormatConditions(.FormatConditions.Count).Interior.Gradient.ColorStops.Add (0)
' T R Y I N G T O F I G U R E O U T G R A D I E N T - S H A D I N G.
' T H E F O L L O W I N G F O U R L I N E S W I T H D O U B L E ' ' C O M M E N T S
' N E E D T O "F I T" I N B U T I D O N O T H O W T O M O D I F Y T H E M
' T O G E T T H E M T O W O R K.
' ' .FormatConditions(.FormatConditions.Count).Interior.Gradient.ThemeColor = xlThemeColorDark1
' ' .FormatConditions(.FormatConditions.Count).Interior.Gradient.TintAndShade = 0
' End With
.FormatConditions(.FormatConditions.Count).Interior.Gradient.ColorStops.Add (1)
' ' .FormatConditions(.FormatConditions.Count).Interior.Gradient.Color = 16711680
' ' .FormatConditions(.FormatConditions.Count).Interior.Gradient.TintAndShade = 0
' End With
.FormatConditions(.FormatConditions.Count).StopIfTrue = False
End With
End If
Next
End Sub
Code:
Sub Macro1()
'
' Macro1 Macro
'
'
' G10 --------------------------------------------------------------------
Selection.FormatConditions.Add Type:=xlTextString, String:="abcdef", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 0
.Gradient.ColorStops.Clear
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
.Color = 255
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
' G11 --------------------------------------------------------------------
Range("G11").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="123456", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = True
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 0
.Gradient.ColorStops.Clear
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
.Color = 65280
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
' G12 --------------------------------------------------------------------
Range("G12").Select
Selection.FormatConditions.Add Type:=xlTextString, String:="xyz", _
TextOperator:=xlContains
Selection.FormatConditions(Selection.FormatConditions.Count).SetFirstPriority
With Selection.FormatConditions(1).Font
.Bold = True
.Italic = False
.Underline = xlUnderlineStyleSingle
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior
.Pattern = xlPatternLinearGradient
.Gradient.Degree = 0
.Gradient.ColorStops.Clear
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(0)
.ThemeColor = xlThemeColorDark1
.TintAndShade = 0
End With
With Selection.FormatConditions(1).Interior.Gradient.ColorStops.Add(1)
.Color = 16711680
.TintAndShade = 0
End With
Selection.FormatConditions(1).StopIfTrue = False
Range("G12").Select
End Sub
P.S. Why is it sometimes, probably 50% of the time I try to Record Macro, it doesn't work and I only get:
Code:
Sub Macro1()
'' Macro1 Macro'
'
End Sub
Attachments
Last edited: