Chart series point coloring no longer works on new files

gdesreu

Active Member
Joined
Jul 30, 2012
Messages
318
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
VBA Code:
.Points(iCategory).MarkerForegroundColor = rCategory.Interior.Color
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

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
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
This is just a guess, but I suspect that there has been a change in the object model which makes rCategory an invalid name. Try replacing all occurrences of rCategory with a different name like rngCat.

Hope that helps.

Regards,
Ken
 
Upvote 0
Hi Ken,

I gave it a try but it still gives me the same error. At first I thought it might be because I got a new PC but my old files still run the code just fine on my new PC. Its just when I try it on a new file. I even copied the chart from a working file and pasted it into a new file and I got the error. Its gotta be something I'm doing differently between the old files and new, but I'm just not seeing it.

Thanks for the help.
 
Upvote 0
I don't know how to help any further without some additional understanding of your problem. Specifically, what data is in HDrange, what is the chart type, etc. Some sample data would be very helpful.

Regards,
Ken
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,323
Members
452,635
Latest member
laura12345

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top