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

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Ok, how about
VBA Code:
Sub ListSheets()
   Dim ws As Worksheet
   Dim i As Long
   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
   With Sheets("Index").Range("A3").Validation
      .Delete
      .Add xlValidateList, , , Join(Application.Sort(ArrayValues, , , 1), ",")
   End With
End Sub
 
Upvote 0
Sorry Fluff

Run-time error '1004': Application-defined or object-defined error → line. .Add xlValidateList, , , Join(Application.Sort(ArrayValues, , , 1), ",")
 
Upvote 0
Try it like
VBA Code:
      .Add xlValidateList, , , Join(ArrayValues, ",")
although the list will not be sorted.
 
Upvote 0
Hi
Debug.Print Join(ArrayValues, ", ") → this prints the list
.Add xlValidateList, , , Join(ArrayValues, ","). → Run-time error '1004': Application-defined or object-defined error :(
 
Upvote 0
I want to choose the worksheet, for use in this code. Here I have to navigate to sheet & activate it to run the code. If I can select the sheet, then I can do it from Index sheet. Thank you
VBA Code:
Sub MyDateFilter()
    'Set Variable, got to declare them in advance'
    Dim lngStart As String, lngEnd As String, ws As Workshee
   
    Set ws = ActiveSheet      'Set active sheet to a variable, so u cud switch back to it'
    'Do The Filters,
    With ActiveSheet.Cells(1, 1).CurrentRegion    'CurrentRegion is dynamic''
        .AutoFilter 1, ">=" & CLng(CDate(lngStart)), 1, "<=" & CLng(CDate(lngEnd))
    End With
    'Still working with Active sheet, Select A1, so wud include headers'
    Range("A1").Select
    Range(Selection, Selection.End(xlToRight)).Select       'Select row end'
    Range(Selection, Selection.End(xlDown)).Select          'Select column end, last cell in Column'
    Selection.Copy                  'Copy Selection'
    'If you do not want to paste, comment out from here to end'
Sheets("Index").Select      'Select workSheet to Paste'
Range("a12").Select         'Select cell where u want to paste to start'
Selection.PasteSpecial xlPasteValues    'Paste'

ws.Select   ' reSelect the worksheet to remove the Filter'
With ActiveSheet.Cells(1, 1).CurrentRegion
        .AutoFilter 1      'no Filters'
    End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,284
Members
452,630
Latest member
OdubiYouth

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