I have the following code that should simply change the decoration of the named range based on there being a value within it. If its empty it turns red and if its not it should clear all decoration. I have looked at the other questions with similar errors and cannot seem to fix my issue. I have the following code:
For Each section In mandatoryFields
MsgBox (ThisWorkbook.Worksheets("Worksheet").Range(section).Value)
If Trim(ThisWorkbook.Worksheets("Worksheet").Range(section).Value) = "" Then
ThisWorkbook.Worksheets("Worksheet").Range(section).Select
With Selection.Interior
.Pattern = xlSolid
.PatternColorIndex = xlAutomatic
.Color = 255
.TintAndShade = 0
.PatternTintAndShade = 0
End With
Else
ThisWorkbook.Worksheets("Worksheet").Range(section).Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
End If
Next section
I have stepped through the code and the runtime error is being triggered at the
.Pattern = xlNone
or
.Pattern = xlSolid
lines. Any Suggestions?
I have also tried
Worksheets("Worksheet").Activate
Range(section).Select
With Selection.Interior
.Pattern = xlNone
.TintAndShade = 0
.PatternTintAndShade = 0
End With
I have the following code which is triggered on a button click.
Dim wb As Workbook
Set wb = Application.Workbooks("C New Hire")
wb.Worksheets("Worksheet").Range("nameRange").Value = "r"
A runtime error will occur on the second time i click the button on the line
wb.Worksheets("Worksheet").Range("nameRange").Value = "r"