• Skip to main content
  • Skip to header right navigation
  • Skip to site footer

My Online Training Hub

Learn Dashboards, Excel, Power BI, Power Query, Power Pivot

  • Courses
  • Pricing
    • Free Courses
    • Power BI Course
    • Excel Power Query Course
    • Power Pivot and DAX Course
    • Excel Dashboard Course
    • Excel PivotTable Course – Quick Start
    • Advanced Excel Formulas Course
    • Excel Expert Advanced Excel Training
    • Excel Tables Course
    • Excel, Word, Outlook
    • Financial Modelling Course
    • Excel PivotTable Course
    • Excel for Customer Service Professionals
    • Excel for Operations Management Course
    • Excel for Decision Making Under Uncertainty Course
    • Excel for Finance Course
    • Excel Analysis ToolPak Course
    • Multi-User Pricing
  • Resources
    • Free Downloads
    • Excel Functions Explained
    • Excel Formulas
    • Excel Add-ins
    • IF Function
      • Excel IF Statement Explained
      • Excel IF AND OR Functions
      • IF Formula Builder
    • Time & Dates in Excel
      • Excel Date & Time
      • Calculating Time in Excel
      • Excel Time Calculation Tricks
      • Excel Date and Time Formatting
    • Excel Keyboard Shortcuts
    • Excel Custom Number Format Guide
    • Pivot Tables Guide
    • VLOOKUP Guide
    • ALT Codes
    • Excel VBA & Macros
    • Excel User Forms
    • VBA String Functions
  • Members
    • Login
  • Blog
  • Excel Webinars
  • Excel Forum
    • Register as Forum Member

Get lists of graphs and tables in the Excel problem|VBA & Macros|Excel Forum|My Online Training Hub

You are here: Home / Get lists of graphs and tables in the Excel problem|VBA & Macros|Excel Forum|My Online Training Hub

vba course banner

Avatar
sp_LogInOut Log In sp_Registration Register
sp_Search Search
Advanced Search
Search
Forum Scope




Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Search Search
sp_RankInfo
Lost password?
sp_CrumbsHome HomeExcel ForumVBA & MacrosGet lists of graphs and tables in t…
sp_PrintTopic sp_TopicIcon
Get lists of graphs and tables in the Excel problem
Avatar
Andrej Veternik

New Member
Members
Level 0
Forum Posts: 1
Member Since:
February 16, 2022
sp_UserOfflineSmall Offline
1
February 16, 2022 - 9:25 pm
sp_Permalink sp_Print sp_EditHistory

SOLVED...

 

i,
I found this code online (Sigma Coding) which would suit to my needs of getting names of Charts and Tables in excel workbook.
Howeever, I have the problem taht i get into validate list only the last chart/table entry in the array and cannot figure out what is wrong. With the debug.print I get the lisitng in the array and it is correct:
Tabela1-Export-ListObject
Grafikon1-Costs-ChartObject
Grafikon2-Costs-ChartObject
Tabela25-Costs-ListObject
graf_Sales-Sales-ChartObject
Tabela3-Sales-ListObject

However in the drow down list I get only the last one (Tabela3-Sales-ListObject). I assume it is the problem within the .Add Type line. Would somebody help me? The code is listed below.

Thank you and BR,
Andrej

------------------------------------------------------------------
Sub UpdateDropdownColumn()

Dim xlBook As Workbook
Dim xlSheet As Worksheet
Dim xlTable As ListObject
Dim xlTableColumn As ListColumn
Dim xlChartObject As ChartObject
Dim xlTableObject As ListObject

Dim ObjectArray() As String
Dim ObjectArrayIndex As Integer

'set the book
Set xlBook = ThisWorkbook

'Loop trough each worksheet

For Each xlSheet In xlBook.Worksheets

'if we have Chart
If xlSheet.ChartObjects.Count > 0 Then

'Grap each chart name
For Each xlChartObject In xlSheet.ChartObjects

'Update the count
ObjectArrrayIndex = ObjectArrayIndex + 1
ReDim Preserve ObjectArray(ObjectArrayIndex)

'Add the chart object to the array
ObjectArray(ObjectArrayIndex) = xlChartObject.Name & "-" & xlSheet.Name & "-" & TypeName(xlChartObject)
Debug.Print ObjectArray(ObjectArrayIndex)
Next
End If

'if we have table
If xlSheet.ListObjects.Count > 0 Then

'Grap each chart name
For Each xlTableObject In xlSheet.ListObjects

'Update the count
ObjectArrrayIndex = ObjectArrayIndex + 1
ReDim Preserve ObjectArray(ObjectArrayIndex)

'Add the chart object to the array
ObjectArray(ObjectArrayIndex) = xlTableObject.Name & "-" & xlSheet.Name & "-" & TypeName(xlTableObject)

Next
End If

Debug.Print ObjectArray(ObjectArrayIndex)

Next
'Grab the sheet
Set xlSheet = xlBook.Worksheets("Export")

'Grab the table from the sheet
Set xlTable = xlSheet.ListObjects("Tabela1")

'grab the Object Column from my table
Set xlTableColumn = xlTable.ListColumns("Graphs")

'Set the validation dropdown
With xlTableColumn.DataBodyRange.Validation

'delete the old one
.Delete

'add the new data to the dropdown,
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=Join(ObjectArray, ",")

'make sure it is a dwopdown
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True

End With
End Sub

-------------------------------------------------

Avatar
Catalin Bombea
Iasi, Romania
Admin
Level 10
Forum Posts: 1826
Member Since:
November 8, 2013
sp_UserOfflineSmall Offline
2
February 17, 2022 - 4:21 pm
sp_Permalink sp_Print

Have you checked if there is something in that array?

What gets printed if you add this line before adding the validation:

Debug.Print Join(ObjectArray, ",")

I assume the sheet is not protected.

sp_Feed
Go to top
Forum Timezone: Australia/Brisbane
Most Users Ever Online: 245
Currently Online: Velouria, jonhn wikal, David du Toit
Guest(s) 9
Currently Browsing this Page:
1 Guest(s)
Top Posters:
SunnyKow: 1432
Anders Sehlstedt: 873
Purfleet: 414
Frans Visser: 346
David_Ng: 306
lea cohen: 222
Jessica Stewart: 218
A.Maurizio: 202
Aye Mu: 201
jaryszek: 183
Newest Members:
Karen Newman
Aminu Sule
Samuel Ramirez
Abdifatah Osman
mohad borhom
Abayomi Adedeji
Ganesh MVS
Gilbert Lemek
Ashleigh Farquharson
Jayz Luu
Forum Stats:
Groups: 3
Forums: 24
Topics: 6364
Posts: 27830

 

Member Stats:
Guest Posters: 49
Members: 32347
Moderators: 3
Admins: 4
Administrators: Mynda Treacy, Philip Treacy, Catalin Bombea, FT
Moderators: MOTH Support, Velouria, Riny van Eekelen
© Simple:Press —sp_Information

Sidebar

Blog Categories

  • Excel
  • Excel Charts
  • Excel Dashboard
  • Excel Formulas
  • Excel PivotTables
  • Excel Shortcuts
  • Excel VBA
  • General Tips
  • Online Training
  • Outlook
  • Power Apps
  • Power Automate
  • Power BI
  • Power Pivot
  • Power Query
microsoft mvp logo
trustpilot excellent rating
Secured by Sucuri Badge
MyOnlineTrainingHub on YouTube Mynda Treacy on Linked In Mynda Treacy on Instagram Mynda Treacy on Twitter Mynda Treacy on Pinterest MyOnlineTrainingHub on Facebook
 

Company

  • About My Online Training Hub
  • Disclosure Statement
  • Frequently Asked Questions
  • Guarantee
  • Privacy Policy
  • Terms & Conditions
  • Testimonials
  • Become an Affiliate

Support

  • Contact
  • Forum
  • Helpdesk - For Technical Issues

Copyright © 2023 · My Online Training Hub · All Rights Reserved. Microsoft and the Microsoft Office logo are trademarks or registered trademarks of Microsoft Corporation in the United States and/or other countries. Product names, logos, brands, and other trademarks featured or referred to within this website are the property of their respective trademark holders.