Remove graph series references of deleted columns - avoid #REF! error

TurpsUK

New Member
Joined
Apr 6, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
Hi All,

I have a 4 sets of data in a sheet that is received through various formulas and displayed as a table. The data itself is used to plot an XY scatter. X is always fixed but the number of column value sets for Y can vary from 3 to 5, depending upon the source data, meaning the graphical data series can be 3, 4 or 5.
I've adapted a macro (below) using reference words to delete certain columns, that works well enough, courtesy of Joe4. Deleting columns based on criteria in a specified row .
However, when the graph #REF! error gets introduced, I'd like to remove those data series automatically, in the VBA code. Can anyone help with this? There are 4 graphs

And yes - the existing code references a Womble! :-) . Idea here - something regular users would not normally write, working in excel to avoid undue column deletion.

Thank you,
Turps

Sub Delete_columns_cassette()

Dim c As Long

Sheets("Cassette").Select
Application.ScreenUpdating = False

'Loop through columns with key word

For c = 56 To 1 Step -1
If Cells(1, c).Value = "Orinoco" Then Cells(1, c).EntireColumn.Delete
Next c

Application.ScreenUpdating = True


End Sub
 
I managed to figure this out myself, with amended code

Sub Delete_columns_cassette()

Dim c As Long

Sheets("Cassette").Select
Application.ScreenUpdating = False

'Loop through columns with key word

For c = 56 To 1 Step -1
If Cells(89, c).Value = "Orinoco" Then Cells(89, c).EntireColumn.Delete
Next c

Sheets("Cassette").Select

'Remove graph series dependent upon count of graph series in Cell A89. Blank if <3, or >4

If Cells(89, 1).Value = "" Then

End If

If Cells(89, 1).Value = "4" Then

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.FullSeriesCollection(5).Delete

ElseIf Cells(89, 1).Value = "3" Then

ActiveSheet.ChartObjects("Chart 1").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveChart.FullSeriesCollection(4).Delete
ActiveSheet.ChartObjects("Chart 2").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveChart.FullSeriesCollection(4).Delete
ActiveSheet.ChartObjects("Chart 3").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveChart.FullSeriesCollection(4).Delete
ActiveSheet.ChartObjects("Chart 4").Activate
ActiveChart.FullSeriesCollection(5).Delete
ActiveChart.FullSeriesCollection(4).Delete

End If

Application.ScreenUpdating = True

End Sub
 
Upvote 0

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