Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - select a range including a hidden column

Tags:

excel

vba

I have put together this code to select non continuous cells of a table to create a graph (the number of rows of the table varies)

Sub graphB()
  Dim sht As Worksheet
  Dim LastRow As Long

  Set sht = ThisWorkbook.Worksheets("CF_total")

  LastRow = sht.Range("E2").CurrentRegion.Rows.Count

  ActiveSheet.Shapes.AddChart.Select

  Set myRange = Union(Range(sht.Cells(2, 5), sht.Cells(LastRow, 5)), Range(sht.Cells(2, 12), sht.Cells(LastRow, 12)))

  ActiveChart.SetSourceData Source:=myRange
  ActiveChart.ChartType = xlPie
End Sub

But now I have decided to hide column number 12 of the worksheet (which contains the data that I want to plot) and it does not work anymore. Any ideas on how I could solve this?

like image 534
Vadx Avatar asked Dec 27 '25 16:12

Vadx


1 Answers

The VBA for that is,

ActiveChart.PlotVisibleOnly = False

See Chart.PlotVisibleOnly Property for more.