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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,796
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:

rawrs

New Member
Joined
Apr 23, 2016
Messages
7
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.
 

veyselemre

Board Regular
Joined
Mar 16, 2006
Messages
55
Code:
Dim AllSheets As Sheets
Set AllSheets = Sheets(Array("Sayfa2", "Sayfa3"))
AllSheets.Delete
 
Last edited:

rawrs

New Member
Joined
Apr 23, 2016
Messages
7
Thank you very much. any idea how to select a range with that? I can't select it on mine.
 

veyselemre

Board Regular
Joined
Mar 16, 2006
Messages
55
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
 

mikerickson

MrExcel MVP
Joined
Jan 15, 2007
Messages
22,796
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
 

rawrs

New Member
Joined
Apr 23, 2016
Messages
7
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
 

rawrs

New Member
Joined
Apr 23, 2016
Messages
7
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?
 

Forum statistics

Threads
1,082,135
Messages
5,363,345
Members
400,729
Latest member
Lisa McConachy

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top