Results 1 to 6 of 6

Copying specific rows from an open workbook into the next row of a closed workbook.

Threaded View

Deimola Copying specific rows from an... 09-05-2012, 11:20 AM
arlu1201 Re: Copying specific rows... 09-05-2012, 11:42 AM
arlu1201 Re: Copying specific rows... 09-05-2012, 11:44 AM
Deimola Re: Copying specific rows... 09-05-2012, 11:56 AM
arlu1201 Re: Copying specific rows... 09-05-2012, 12:56 PM
Deimola Re: Copying specific rows... 09-05-2012, 12:59 PM
  1. #1
    Registered User
    Join Date
    09-05-2012
    Location
    Philadelphia, USA
    MS-Off Ver
    2010
    Posts
    3

    Copying specific rows from an open workbook into the next row of a closed workbook.

    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
    Last edited by arlu1201; 09-05-2012 at 12:01 PM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1