list of worksheet and dialogbox to select

luckyearl

New Member
Joined
Nov 6, 2016
Messages
31
Office Version
  1. 365
  2. 2019
Platform
  1. MacOS
Hi
I am trying to get list of all worksheets, popup Dialog box to select a worksheet, then work with it.
I thought cud store the sheetname in array, but does not work, please suggest. Thank you
VBA Code:
Sub ListSheets()
Dim ws As Worksheet
Dim i As Integer
Dim ArrayValues As ArrayList         ' This does not work'
Set ArrayValues = New ArrayList        ' This does not work'
 
 For i = 1 To ThisWorkbook.Worksheets.Count
         ArrayValues.Add ThisWorkbook.Worksheets(i).name
    Next sht
ListBox1.List = ArrayValues
End Sub
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Do you want the list sorted?
 
Upvote 0
yes please, i gues it would be easier to look for particular worksheet
Thank you
 
Upvote 0
Ok, how about
VBA Code:
Sub ListSheets()
Dim ws As Worksheet
Dim i As Integer
Dim ArrayValues As Object
Set ArrayValues = CreateObject("system.collections.arraylist")
 
 For i = 1 To ThisWorkbook.Worksheets.Count
         ArrayValues.Add ThisWorkbook.Worksheets(i).Name
    Next i
    ArrayValues.Sort
ListBox1.List = ArrayValues.toarray
End Sub
 
Upvote 0
Thank you for help

Got an Run-time error '429', ActiveX component cant create object ? is it due to Macos
Cheers
 
Upvote 0
Yes it is, you cannot use activex components on a Mac.

I suggest that you update your Account details (or click your user name at the top right of the forum) so helpers always know what Excel version(s) & platform(s) you are using as the best solution often varies by version. (Don’t forget to scroll down & ‘Save’)
 
Upvote 0
Thanks for that, how about
VBA Code:
Sub ListSheets()
Dim ws As Worksheet
Dim i As Integer
Dim ArrayValues As Variant
ReDim ArrayValues(1 To ThisWorkbook.Worksheets.Count)
 For i = 1 To ThisWorkbook.Worksheets.Count
         ArrayValues(i) = ThisWorkbook.Worksheets(i).Name
    Next i
ListBox1.List = ArrayValues
End Sub
 
Upvote 0
Thanks for that, how about
VBA Code:
Sub ListSheets()
Dim ws As Worksheet
Dim i As Integer
Dim ArrayValues As Variant
ReDim ArrayValues(1 To ThisWorkbook.Worksheets.Count)
 For i = 1 To ThisWorkbook.Worksheets.Count
         ArrayValues(i) = ThisWorkbook.Worksheets(i).Name
    Next i
ListBox1.List = ArrayValues
End Sub
Thank you, tells me → Object required :(
 
Upvote 0

Forum statistics

Threads
1,214,908
Messages
6,122,187
Members
449,071
Latest member
cdnMech

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