Hi, hoping someone can assist with using VBA to export worksheets. I have a workbook which has 30 reports (on separate worksheets) plus some other worksheets. One of the others worksheets is called "Export" which allows the user to select which reports to extracts using Range A1:A30. This range does match the worksheet name for each report.
I am trying to export the reports that have been selected in the export tab to their very own individual worksheet. There are a few others things I want to do but I'm sure I can work those out if I have a framework to work with.
I have this but it only copies the selected reports to just one workbook. Any ideas?? Any help would be massively appreciated.
Sub testArray()
Dim myArray() As String
Dim myRange As Range
Dim Cell As Range
Dim OldBook As String
Dim newBook As String
Dim a As Long
Set myRange = Application.Range(Cell1:="Export!A1:A30")
'Or the range with your sheetnames
OldBook = ActiveWorkbook.Name
For Each Cell In myRange
If Not Cell = "" Then
a = a + 1
ReDim Preserve myArray(1 To a)
myArray(a) = Cell
End If
Next
For a = 1 To UBound(myArray)
If a = 1 Then
Sheets(myArray(a)).Copy
newBook = ActiveWorkbook.Name
Workbooks(OldBook).Activate
Else
Sheets(myArray(a)).Copy After:=Workbooks(newBook).Sheets(a - 1)
Workbooks(OldBook).Activate
End If
Next
End Sub
I am trying to export the reports that have been selected in the export tab to their very own individual worksheet. There are a few others things I want to do but I'm sure I can work those out if I have a framework to work with.
I have this but it only copies the selected reports to just one workbook. Any ideas?? Any help would be massively appreciated.
Sub testArray()
Dim myArray() As String
Dim myRange As Range
Dim Cell As Range
Dim OldBook As String
Dim newBook As String
Dim a As Long
Set myRange = Application.Range(Cell1:="Export!A1:A30")
'Or the range with your sheetnames
OldBook = ActiveWorkbook.Name
For Each Cell In myRange
If Not Cell = "" Then
a = a + 1
ReDim Preserve myArray(1 To a)
myArray(a) = Cell
End If
Next
For a = 1 To UBound(myArray)
If a = 1 Then
Sheets(myArray(a)).Copy
newBook = ActiveWorkbook.Name
Workbooks(OldBook).Activate
Else
Sheets(myArray(a)).Copy After:=Workbooks(newBook).Sheets(a - 1)
Workbooks(OldBook).Activate
End If
Next
End Sub