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

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Perhaps

Code:
Dim AllSheets as Worksheets

Set AllSheets = ThisWorkbook.Sheets(Array("Item Analysis", "Analysis", "Make", "Carrier Analysis", "iPhoneCarrierGB", "iPhoneGB")

What do you want to do with these sheets once you have them in one Worksheets object?
 
Last edited:
Upvote 0
They all have the same layout. I want to apply changes and adjustments to all of them.

Also, i get a "Type Mismatch" error with that.
 
Upvote 0
Code:
Dim AllSheets As Sheets
Set AllSheets = Sheets(Array("Sayfa2", "Sayfa3"))
AllSheets.Delete
 
Last edited:
Upvote 0
Thank you very much. any idea how to select a range with that? I can't select it on mine.
 
Upvote 0
Code:
    Dim AllSheets As Sheets
    Dim sh As Worksheet
    Set AllSheets = Sheets(Array("Sayfa3", "Sayfa2"))
    AllSheets.Select
    Range("A1:K1").Select
    Selection.Interior.Color = vbYellow
 
Upvote 0
Or perhaps
Code:
Dim AllSheets As Sheets

Set AllSheets = ThisWorkbook.Sheets(Array("sheet1", "sheet2", "Sheet3"))
With AllSheets
    .Item(1).Range("A1:A10").Interior.ColorIndex = 6
    .FillAcrossSheets .Item(1).Range("A1:A10"), xlFillWithFormats
End With
 
Upvote 0
Or perhaps
Code:
Dim AllSheets As Sheets

Set AllSheets = ThisWorkbook.Sheets(Array("sheet1", "sheet2", "Sheet3"))
With AllSheets
    .Item(1).Range("A1:A10").Interior.ColorIndex = 6
    .FillAcrossSheets .Item(1).Range("A1:A10"), xlFillWithFormats
End With

None of this works. I don't understand why it's working in your VBA editor and not mine. It doesn't seem possible that it works in yours and not in mine. This is so simple and vba is making it so hard
 
Upvote 0
Or perhaps
Code:
Dim AllSheets As Sheets

Set AllSheets = ThisWorkbook.Sheets(Array("sheet1", "sheet2", "Sheet3"))
With AllSheets
    .Item(1).Range("A1:A10").Interior.ColorIndex = 6
    .FillAcrossSheets .Item(1).Range("A1:A10"), xlFillWithFormats
End With
taking out the .filacrosssheets part of your code, this only works on 1 page because you have to select a range for .Item(range).

Why can't I just add these to all of my sheets?
 
Upvote 0

Forum statistics

Threads
1,214,584
Messages
6,120,385
Members
448,956
Latest member
JPav

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