tcarter963
New Member
- Joined
- Aug 3, 2006
- Messages
- 38
I'm trying to copy some data to a new workbook all on one worksheet from multiple sheets in another workbook. My code keeps breaking at the point where it makes a new workbook (.SaveAs Filename). It gives runtime error 1004. I'm not sure I have the copy values set correctly either but can't test it because the code breaks before then. Any help would be really appreciated.
Code:
Option Explicit
Sub Cp2NewWorkBook()
Dim Newbook As Workbook
Dim strName As String
strName = InputBox(Prompt:="Enter Project Number", _
Title:="Save Averaged data in database project folder", _
Default:="12000")
On Error GoTo ErrHandler:
ErrHandler:
If Err.Number = 76 Then
MsgBox "The folder for this project has not been created yet, the path cannot be found.", vbInformation
Exit Sub
End If
If strName = "12000" Or strName = vbNullString Then
Exit Sub
Else
Set Newbook = Workbooks.Add
With Newbook
.Title = "Average Results"
.Subject = "Ave"
.SaveAs Filename:="N:\_HPLCDatabase\" & strName & "\AveReuslts.xls"
End With
End If
Dim WS As Worksheet
Dim LastRowColumnA As Long
Dim LastRowColumnBA As Long
Dim wbX As Workbook
Set wbX = ActiveWorkbook
For Each WS In wbX
Application.ScreenUpdating = False
LastRowColumnBA = wbX.WS.Range("BA301").End(xlUp).Row
LastRowColumnA = Newbook.Range("A3000").End(xlUp).Row
Newbook.Range("A1:J" & LastRowColumnA).Value = WS.Range("BA2:BJ" & LastRowColumnBA).Value
On Error Resume Next
Next WS
Application.ScreenUpdating = True
End Sub