Hi,
I have some code that I have used for years on other files. Those files still work just fine when I open them. I have copied the code to a new file but I am getting a "Object variable or With Block variable not set" error at
The rCategory is set to nothing which is what I think is causing it. I have no idea why my old files work fine but when I try to recreate them in a new file I get this error. Any help is appreciated. I was up till midnight last night trying to resolve this but I am at a loss and can't figure it out. Thanks
I have some code that I have used for years on other files. Those files still work just fine when I open them. I have copied the code to a new file but I am getting a "Object variable or With Block variable not set" error at
VBA Code:
.Points(iCategory).MarkerForegroundColor = rCategory.Interior.Color
VBA Code:
Private Sub CommandButton1_Click()
Dim rPatterns As Range
Dim iCategory As Long
Dim vCategories As Variant
Dim rCategory As Range
Dim HDrange As String
Dim HDrng1 As String
Dim HDrng2 As String
HDrng1 = Sheets("Sheet1").Range("d2").Row
HDrng2 = Sheets("sheet1").Range("d2").End(xlDown).Row
HDrange = "(d" & HDrng1 & ":" & "d" & HDrng2 & ")"
Set rPatterns = Sheets("sheet1").Range(HDrange)
ActiveSheet.ChartObjects("Chart 1").Select
With ActiveChart.SeriesCollection(1)
vCategories = .XValues
For iCategory = 1 To UBound(vCategories)
Set rCategory = rPatterns.Find(What:=vCategories(iCategory))
.Points(iCategory).MarkerForegroundColor = rCategory.Interior.Color
Next
End With
End Sub