Hello,
I've been using code that I've got from previous posts and from FAQ's. I'm trying to copy all the sheets in my workbook (with some exclusions), starting at row 15 and going to the end. I will then paste them to one single sheet at the bottom of the active selection.
So I thought I'd do this by first opening a form and loading a listbox of all the sheets I want. This pit works fine.
Then I'd cycle through the sheets and copy the active range from row 15 (this bit isn't working I don't think)
Then I'd paste it at the bottom of the active range in the chosen sheet (called Overall).
When I press my command button which triggers all this off I get an application-defined or object-defined error. This seems to be pointing to the copy code.
Can anyone help me or point me in the right direction to get a different method to do this.
many thanks
I've been using code that I've got from previous posts and from FAQ's. I'm trying to copy all the sheets in my workbook (with some exclusions), starting at row 15 and going to the end. I will then paste them to one single sheet at the bottom of the active selection.
So I thought I'd do this by first opening a form and loading a listbox of all the sheets I want. This pit works fine.
Then I'd cycle through the sheets and copy the active range from row 15 (this bit isn't working I don't think)
Then I'd paste it at the bottom of the active range in the chosen sheet (called Overall).
When I press my command button which triggers all this off I get an application-defined or object-defined error. This seems to be pointing to the copy code.
Code:
Private Sub UserForm_Initialize()
'populate listbox with all sheets except exclusions
Dim wbs As Worksheet
For Each wbs In Worksheets
If wbs.Name <> "Contents" Then
If wbs.Name <> "Status" Then
If wbs.Name <> "Introduction" Then
If wbs.Name <> "Template" Then
If wbs.Name <> "Overall" Then
ListBox1.ColumnCount = 2
ListBox1.AddItem wbs.Name
End If
End If
End If
End If
End If
Next
'copy sheets in listbox
Dim i As Long
For i = 0 To Me.ListBox1.ListCount - 1
If Me.ListBox1.Selected(i) = False Then
Dim LastRow As Long
Dim FirstRow As Long
Dim LastCol As Integer
Dim FirstCol As Integer
' Find the FIRST real row
FirstRow = Sheets(Me.ListBox1.List(i)).Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByRows).Row
' Find the FIRST real column
FirstRow = Sheets(Me.ListBox1.List(i)).Cells.Find(What:="*", _
SearchDirection:=xlNext, _
SearchOrder:=xlByRows).Column
' Find the LAST real row
LastRow = Sheets(Me.ListBox1.List(i)).Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row
' Find the LAST real column
LastCol = Sheets(Me.ListBox1.List(i)).Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByColumns).Column
'Select the ACTUAL Used Range as identified by the
'variables identified above
Worksheets(Me.ListBox1.List(i)).Range(Cells(15, 1), _
Cells(LastRow, LastCol)).Copy
'paste copied code to overall sheet
'Dim laRow As Long
' Find the FIRST EMPTY row by adding 1 to the last row
laRow = ActiveSheet.Cells.Find(What:="*", _
SearchDirection:=xlPrevious, _
SearchOrder:=xlByRows).Row + 1
'Paste the data into the first
'COMPLETELY empty row
Sheets("Overall").Paste Destination:=Cells(laRow, 1)
Application.DisplayAlerts = True
End If
Next i
Unload Me
End Sub
Can anyone help me or point me in the right direction to get a different method to do this.
many thanks