Naming and Selecting All Worksheets VBA

rawrs

New Member
Joined
Apr 23, 2016
Messages
7
Hi all.

Been at this for 5 hours....I can't find a way to name all my worksheets, then make a variable that would select them all. Speed and cleanliness in the code is very important to me, so any optimal or much better ways would be very appreciated. Here's my code:

Code:
Sub meow()    Dim count As Integer
    Dim i As Integer
    
    Dim dNames(1 To 6) As Variant
        items = Worksheets("Item Analysis").Activate
        analysis = Worksheets("Analysis").Activate
        manuf = Worksheets("Make").Activate
        carrier = Worksheets("Carrier Analysis").Activate
        gbCarrier = Worksheets("iPhoneCarrierGB").Activate
        gb = Worksheets("iPhoneGB").Activate
    
    Set all = ActiveWorkbook.Sheets(items, analysis, manuf, carrier, gbCarrier, gb)
    
    
End Sub
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
To select all sheets you can use this:
Code:
Sheets.Select

To do other tasks on all sheets why not do this:
Code:
Sub Fill_All_Sheets()
Dim i As Long

    For i = 1 To Sheets.Count
        Sheets(i).Range("A1:A10").Value = "Bob"
    Next
End Sub
 
Upvote 0
To select all sheets you can use this:
Code:
Sheets.Select

To do other tasks on all sheets why not do this:
Code:
Sub Fill_All_Sheets()
Dim i As Long

    For i = 1 To Sheets.Count
        Sheets(i).Range("A1:A10").Value = "Bob"
    Next
End Sub
Thank you so much. I realize that I asked for all sheets in the question, but I meant select some sheets.

Nonetheless, your answer gave me the information to get it working. Thank you
 
Upvote 0

Forum statistics

Threads
1,215,430
Messages
6,124,846
Members
449,194
Latest member
HellScout

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