Hi all, im quite new to vba, i have a code as below,
1. User enter unit and name
2. Check if date & unit and name correct
3. Copy range A8:F30 to new workbook at C:\Users\Abby\VBA\test.xlsx
It is append to next row.
4. Then clear the content that filled after save
There is no bugs when i executed it, but the data is not copied to the new destination. pls help what's wrong with my the script. plssssss...
================================================
Private Sub SaveButton_Click()
If Range("$B$4") = "" Then
MsgBox "Please Select Your Unit and Name"
Exit Sub
End If
With ActiveWorkbook.Sheets("EMB_RISK").Range("$L9:$L30")
If WorksheetFunction.Or(.Cells) = "True" Then
MsgBox "Please Enter DateTime and Details"
Exit Sub
Else
Dim wbkMaster As Workbook
Dim shtMaster As Worksheet
Dim NextRow As Range
Set wbkMaster = Workbooks.Open("C:\Users\Abby\VBA\test.xlsx")
Set shtMaster = wbkMaster.Worksheets(1)
With Sheets("Data")
Set NextRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
shtMaster.Range("$A8:$I30").Copy
NextRow.PasteSpecial Paste:=xlValues, Transpose:=False
Application.CutCopyMode = False
wbkMaster.Close True
Set shtMaster = Nothing
Set wbkMaster = Nothing
Set NextRow = Nothing
End If
End With
Sheets("EMB_RISK").Range("A9:F31") = ""
Sheets("EMB_RISK").Range("B2") = ""
Sheets("EMB_RISK").Range("B4") = ""
End Sub
1. User enter unit and name
2. Check if date & unit and name correct
3. Copy range A8:F30 to new workbook at C:\Users\Abby\VBA\test.xlsx
It is append to next row.
4. Then clear the content that filled after save
There is no bugs when i executed it, but the data is not copied to the new destination. pls help what's wrong with my the script. plssssss...
================================================
Private Sub SaveButton_Click()
If Range("$B$4") = "" Then
MsgBox "Please Select Your Unit and Name"
Exit Sub
End If
With ActiveWorkbook.Sheets("EMB_RISK").Range("$L9:$L30")
If WorksheetFunction.Or(.Cells) = "True" Then
MsgBox "Please Enter DateTime and Details"
Exit Sub
Else
Dim wbkMaster As Workbook
Dim shtMaster As Worksheet
Dim NextRow As Range
Set wbkMaster = Workbooks.Open("C:\Users\Abby\VBA\test.xlsx")
Set shtMaster = wbkMaster.Worksheets(1)
With Sheets("Data")
Set NextRow = .Cells(.Rows.Count, 1).End(xlUp).Offset(1, 0)
End With
shtMaster.Range("$A8:$I30").Copy
NextRow.PasteSpecial Paste:=xlValues, Transpose:=False
Application.CutCopyMode = False
wbkMaster.Close True
Set shtMaster = Nothing
Set wbkMaster = Nothing
Set NextRow = Nothing
End If
End With
Sheets("EMB_RISK").Range("A9:F31") = ""
Sheets("EMB_RISK").Range("B2") = ""
Sheets("EMB_RISK").Range("B4") = ""
End Sub