Input,check, then copy to another worksheet

liewabby

New Member
Joined
Jul 30, 2015
Messages
2
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
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Code:
            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

This is referencing sheet "Data" in the Active workbook. The Active workbook is Test.xlsx because it was just opened previous to setting NextRow. I think you want to set NextRow before you open Test.xlsx.
 
Upvote 0

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top