Hi All,
I'm really new to this and have been trying to code. I'm trying to select a data range and copy it into a file save both files, clear the contents of the original selection and save and close that workbook too.
The below did work:
Sub CommandButton1_Click()
Application.ScreenUpdating = False
If Workbooks("Support Workload Tracker").Worksheets("Data Capture").Range("B2") <> "" Then
Dim AnswerYes As String
Dim AnswerNo As String
AnswerYes = MsgBox("Are you finishing for the day?", vbQuestion + vbYesNo, "End Of Day")
If AnswerYes = vbNo Then
MsgBox "Action Cancelled"
Cancel = True
Else
Workbooks("Support Workload Tracker").Activate
With Worksheets("Data Capture")
LastRow = .Cells(Rows.Count, "N").End(xlUp).Row
.Range("A2:N" & LastRow).Copy
End With
Dim wb As Workbook
Filespec = "xxxxxxx(webaddress)xxxxxxx"
Set wb = Application.Workbooks.Open(Filename:=Filespec)
Workbooks("MASTER Support Workload Tracker").Worksheets("Data").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.PasteSpecial (xlPasteValuesAndNumberFormats)
For Each wb In Workbooks
wb.Save
Next wb
Workbooks("MASTER Support Workload Tracker").Close
End If
End If
Application.ScreenUpdating = True
End Sub
But when I added this after the "Workbooks("MASTER Support Workload Tracker").Close"
Worksheets("Historical").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.PasteSpecial (xlPasteValuesAndNumberFormats)
Workbooks("Support Workload Tracker").Activate
With Worksheets("Data Capture")
LastRow = .Cells(Rows.Count, "N").End(xlUp).Row
.Range("A2:N" & LastRow).ClearContents
It stopped working. Can anyone tell me why? And how to fix it.
For full clarity this is how the code looks currently and isn't working
Sub CommandButton1_Click()
Application.ScreenUpdating = False
If Workbooks("Support Workload Tracker").Worksheets("Data Capture").Range("B2") <> "" Then
Dim AnswerYes As String
Dim AnswerNo As String
AnswerYes = MsgBox("Are you finishing for the day?", vbQuestion + vbYesNo, "End Of Day")
If AnswerYes = vbNo Then
MsgBox "Action Cancelled"
Cancel = True
Else
Workbooks("Support Workload Tracker").Activate
With Worksheets("Data Capture")
LastRow = .Cells(Rows.Count, "N").End(xlUp).Row
.Range("A2:N" & LastRow).Copy
End With
Dim wb As Workbook
Filespec = "xxxxxxxxxx(webaddress)xxxxxxxxx"
Set wb = Application.Workbooks.Open(Filename:=Filespec)
Workbooks("MASTER Support Workload Tracker").Worksheets("Data").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.PasteSpecial (xlPasteValuesAndNumberFormats)
For Each wb In Workbooks
wb.Save
Next wb
Workbooks("MASTER Support Workload Tracker").Close
Worksheets("Historical").Range("A" & Rows.Count).End(xlUp).Offset(1).Select
ActiveCell.PasteSpecial (xlPasteValuesAndNumberFormats)
Workbooks("Support Workload Tracker").Activate
With Worksheets("Data Capture")
LastRow = .Cells(Rows.Count, "N").End(xlUp).Row
.Range("A2:N" & LastRow).ClearContents
End If
End If
Application.ScreenUpdating = True
End Sub
Bookmarks