I am extremely new to Excel VBA.
My goal is to create a command button to open a password protected workbook, automatically copy data from selected cells within specific worksheets and paste into the unprotected workbook. The data also needs to be placed in the next empty row as the data in the protected workbook changes daily.
I have not been able to get around a range error at
Worksheets("Sheet14").Select
xDate = Range("L2")
Run-time error '9': Subscript out of range.
Private Sub CommandButton2_Click()
Workbooks.Open Filename:="P:\source.xlsx", Password:="password"
Dim xDate As String
Dim ACD As String
Dim Untouched As String
Dim DailyAct As String
Dim SchedAdherence As String
Dim Status As String
Worksheets("Sheet14").Select
xDate = Range("L2")
Worksheets("Sheet5").Select
ACD = Range("C4")
Worksheets("Sheet5").Select
DailyAct = Range("E4")
Worksheets("Sheet5").Select
SchedAdherence = Range("F4")
Worksheets("Sheet7").Select
Status = Range("B5")
Set TrackingReport = Workbooks("C:\Destination"): TrackingReport.Activate
Worksheets("Sheet2").Select
Worksheets("Sheet2").Range("B1").Select
RowCount = Worksheets("Sheet2").Range("B1").CurrentRegion.Row.Count
With Worksheets("Sheet2").Range("B1")
.Offset(RowCount, 0) = xDate
.Offset(RowCount, 1) = ACD
.Offset(RowCount, 2) = DailyAct
.Offset(RowCount, 3) = SchedAdherence
.Offset(RowCount, 4) = Status
End With
TrackingReport.Save
Set DailyPerformance = Workbooks.Open("P:\source.xlsx",Password:="password")
DailyPerformance.Close
End Sub