Hi, I am new to this site and relatively new and self taught with VBA. I have a problem with some code where I am trying to copy certain rows of data (columns A:AG) from an open workbook, sheet name "HRIS FIN Sample File" (which will have daily variable length rows but with column data fixed) where a value in row CH = "Change" and append this to a closed workbook to the next free row of data on worksheet "HRIS Log". The closed file will be added to on a daily basis with all previous data added left intact for comment. I have tried the code below and it opens the specified destination file but it will only copy one line before it stops. I also want to save and close the destination file with the code but haven't got anywhere with this at all yet! Any assistance would be very much appreciated. I got the code online and moved the set DWS line as otherwise for each row, the macro tried to reopen the already open file? Thanks for any help!! Nigel.
Sub Copy_Records()
Dim lastline As Long, firstline As Long, i As Long
Dim MWS As Worksheet
Dim DWS As Worksheet
Set MWS = ThisWorkbook.Worksheets("HRIS FIN Sample File")
Set DWS = Workbooks.Open("S:\GFSS - Global Finance Shared Services\Org Admin\HRIS Log\HRIS Log.xlsm").Worksheets("HRIS Log")
lastline = MWS.Range("A1000").End(xlUp).Row
For i = 2 To lastline
If MWS.Range("CH" & i).Value = "Change" Then
'Set DWS = Workbooks.Open("S:\GFSS - Global Finance Shared Services\Org Admin\HRIS Log\HRIS Log\HRIS Log.xlsm").Worksheets("HRIS Log")
If IsEmpty(DWS.Range("A2")) Then
firstline = 2
Else
firstline = DWS.Range("A2").End(xlDown).Row
End If
MWS.Range("A" & i & ":CG" & i).Copy Destination:=DWS.Range("A" & firstline)
End If
Next i
End Sub
Bookmarks