Run-time error 91 Object variable or With block variable not set

cdrako

New Member
Joined
Aug 25, 2010
Messages
19
This was working OK when the range was A1:A3 and then iwhen range changed to B8:B18 I started getting the runtime error.

Any thoughts?


Sub ColorByCategoryLabel()
Dim rPatterns As Range
Dim iCategory As Long
Dim vCategories As Variant
Dim rCategory As Range

Set rPatterns = ActiveSheet.Range("$B$8:$B$18")
With ActiveChart.SeriesCollection(1)
vCategories = .XValues
For iCategory = 1 To UBound(vCategories)
Set rCategory = rPatterns.Find(What:=vCategories(iCategory))
.Points(iCategory).Format.Fill.ForeColor.RGB = rCategory.Interior.Color
Next
End With
End Sub
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
You didn't say which error you're getting, and on which line it occurs. In any case, since your code refers to the active chart, you'll need to make sure that your chart has been selected/activated before running the code. Did you select/activate the chart before running the code?
 
Upvote 0
Sorry.. The error is in the subject line and the line is the one that starts.... .Points(iCategory)

And yes, I have chart selected when the macro is run.
 
Upvote 0
The error probably occurs because it doesn't find one (or more) of the categories within B8:B18. When the error occurs, click on "Debug". The line causing the error will then be highlighted in yellow. Then, if you place your cursor over the variable rCategory in the line above, you'll probably see that it has been assigned Nothing. And if you place your cursor over rCategory.Interior.Color, you should see the error.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,521
Messages
6,179,291
Members
452,902
Latest member
Knuddeluff

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