VBA Sheets(Array).Select mismatch

rrichardlee33

New Member
Joined
Oct 19, 2018
Messages
2
Hi - I am trying to copy and save a number of sheet groups (i.e. sheet 1, 2, 3, and 5 save; sheet 6, 7, 8, and 10 save) and a loop to do this. However I keep getting mismatch on the Sheets(array) section. Any help would be appreciated.

Sub Tabs()
'
' To automatically copy tabs into new excel and save
'
Dim FileName1 As String
Dim FilePath As String
Dim FileName2 As String
Dim TabsArray As Variant

FileName1 = Range("B7") 'file name to copy from
FilePath = Range("B8") 'where file will be saved

Windows("Tab Seperate.xlsm").Activate 'where the code is

For i = 11 To 18 'rows 11 through 18, the save as file names

FileName2 = Cells(i, 2)

TabsArray = Array(Cells(i, 3), Cells(i, 4), Cells(i, 5), Cells(i, 6), Cells(i, 7))

Windows(FileName1).Activate

Sheets(TabsArray).Copy

ActiveWorkbook.SaveAs FileName:= _
FilePath & FileName2

Next

End Sub
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Hi & welcome to MrExcel.
You need to do it like
Code:
TabsArray = Array(Cells(i, 3).Value, Cells(i, 4).Value, Cells(i, 5).Value, Cells(i, 6).Value, Cells(i, 7).Value)
Otherwise its putting the range object into the array, rather than the values
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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