Roderick_E
Well-known Member
- Joined
- Oct 13, 2007
- Messages
- 2,051
Hi there folks,
I know how to press ctrl and select multiple sheets so as to apply something to all selected sheets. But I'm trying to do this in VBA
My following code is supposed to copy the faux header (whatever the user selects, typically the first few rows) which often contains images and copy this to all other visible sheets within the workbook. I know my issue is that my red line would normally have sheets(array("Sheet2","Sheet3")).select and so on but I'm trying to do this dynamically so the quotes aren't actually in my array. It is sheets(array(Sheet2,Sheet3)).select This doesn't work. Please help. Thanks
I know how to press ctrl and select multiple sheets so as to apply something to all selected sheets. But I'm trying to do this in VBA
My following code is supposed to copy the faux header (whatever the user selects, typically the first few rows) which often contains images and copy this to all other visible sheets within the workbook. I know my issue is that my red line would normally have sheets(array("Sheet2","Sheet3")).select and so on but I'm trying to do this dynamically so the quotes aren't actually in my array. It is sheets(array(Sheet2,Sheet3)).select This doesn't work. Please help. Thanks
Code:
Sub copyfauxheader()
Dim sourcesh As Worksheet
Dim wks As Worksheet
Dim wksarraystr As String
Dim wksarray() As String
Selection.Copy
Set sourcesh = ActiveSheet
For Each wks In ThisWorkbook.Sheets
If sourcesh.Name <> wks.Name And wks.Visible = True Then
If wksarraystr = "" Then
wksarraystr = wks.Name
Else
wksarraystr = wksarraystr & "," & wks.Name
End If
wks.Select
wks.Rows(1).Select
End If
Next
wksarray = Split(wksarraystr, ",")
[COLOR=#ff0000] Sheets(Array(wksarray)).Select[/COLOR]
Selection.Insert Shift:=xlDown
sourcesh.Select
Range("A7").Select
Application.CutCopyMode = False
MsgBox "Done"
End Sub