Select multiple sheets listed in a colum

Lidget

New Member
Joined
Apr 14, 2021
Messages
13
Office Version
  1. 2013
Platform
  1. Windows
Hi, I'm new to vba and have mainly been learning by recording.

I currently have a book with 50 named sheets and need to delete info from about 30 of them. I currently have a macro to do this using a select array "sheet 1", "sheet 4"... Etc. I'd rather have this as a list of sheet names on a control sheet so that can be update by other people rather than them going into the code but I can't get it working.

In using:
Dim arrayworksheets As Variant

Arrayworksheets = sheets("control").range("c4:c:100")
Sheets(array(arrayworksheets)).select

...and then just range and clear contents but I get a type mismatch error
 

Excel Facts

Who is Mr Spreadsheet?
Author John Walkenbach was Mr Spreadsheet until his retirement in June 2019.
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Lidget()
   Dim Cl As Range
   Dim UsdRws As Long
   
   With Sheets("Control")
      For Each Cl In .Range("C4", .Range("C" & Rows.Count).End(xlUp))
         If Evaluate("isref('" & Cl.Value & "'!A1)") Then
            Sheets(Cl.Value).Range("A1:F10").ClearContents
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
Hi & welcome to MrExcel.
How about
VBA Code:
Sub Lidget()
   Dim Cl As Range
   Dim UsdRws As Long
  
   With Sheets("Control")
      For Each Cl In .Range("C4", .Range("C" & Rows.Count).End(xlUp))
         If Evaluate("isref('" & Cl.Value & "'!A1)") Then
            Sheets(Cl.Value).Range("A1:F10").ClearContents
         End If
      Next Cl
   End With
End Sub
Thanks for the speedy response. And I understand some of this! Unfortunately it's giving me a type mismatch error...
 
Upvote 0
Do you have any bank cells in col C?
 
Upvote 0
Thanks for the speedy response. And I understand some of this! Unfortunately it's giving me a type mismatch error...
Ignore that, I missed a bracket >_< it's giving that error when there are gaps in the list though...
 
Upvote 0
You can ignore blanks like
VBA Code:
Sub Lidget()
   Dim Cl As Range
   Dim UsdRws As Long
   
   With Sheets("Control")
      For Each Cl In .Range("C4", .Range("C" & Rows.Count).End(xlUp))
         If Cl.Value <> "" Then
            If Evaluate("isref('" & Cl.Value & "'!A1)") Then
               Sheets(Cl.Value).Range("A1:F10").ClearContents
            End If
         End If
      Next Cl
   End With
End Sub
 
Upvote 0
Solution

Forum statistics

Threads
1,215,053
Messages
6,122,882
Members
449,097
Latest member
dbomb1414

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