+ Reply to Thread
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Macro help to copy row from one spreadsheet to another

  1. #1
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Macro help to copy row from one spreadsheet to another

    Hello. I have pretty decent experience with Excel but not with macros. The attached spreadsheet is a tool that I use in the field as I go from site to site. I want to use the "status" status column D to trigger a row copy to the adjacent "priorities" sheet (i.e. if the entry in column D = "incomplete" then copy entire row to "priorities" sheet. I found a macro on the web and plugged it in to the "full report" sheet and it pretty much does what I'm asking for, however, it' creating blank rows and other formatting issues in the "priorities" sheet. Any ideas? Thanks- Scott
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor p24leclerc's Avatar
    Join Date
    07-05-2010
    Location
    Québec
    MS-Off Ver
    Excel 2003-2010
    Posts
    377

    Re: Macro help to copy row from one spreadsheet to another

    try this modified maco:
    Sub test()
    If ActiveSheet.Name <> "Full Report" Then Exit Sub
    LastRow = Range("D" & Rows.Count).End(xlUp).Row
    For Each Cell In Range("D8:D" & LastRow)
      If Cell = "Incomplete" Then
        Cell.EntireRow.Copy
        Sheets("Priorities").Cells(2, 1).Insert Shift:=xlDown
      End If
    Next Cell
    Application.CutCopyMode = False
    End Sub

  3. #3
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,


    Detach/open workbook GetIncomplete - sfoxbox - EF809567 - SDG10.xls and run macro GetIncomplete.
    Attached Files Attached Files
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  4. #4
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro help to copy row from one spreadsheet to another

    Thanks Stan. That works perfectly. However, rows 1 through 7 include generic data that I'd like to have at the top of the "priorities sheet and then have sorted data begin at row 8. Is there a way to do this? Thanks again for your help.

  5. #5
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,

    rows 1 through 7 include generic data that I'd like to have at the top of the "priorities sheet
    Your attached workbook did not have this information in worksheet Priorities.

    Are these 7 rows coming from worksheet Full Report?

    Or, should I just leave the first 7 rows of worksheet Priorities untouched?
    Last edited by stanleydgromjr; 01-15-2012 at 06:47 PM.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  6. #6
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro help to copy row from one spreadsheet to another

    Leaving the first 7 rows of the priorities sheet untouched would be sufficient.

  7. #7
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


    
    Option Explicit
    Sub GetIncompleteV2()
    ' stanleydgromjr, 01/15/2012
    ' http://www.excelforum.com/excel-programming/809567-macro-help-to-copy-row-from-one-spreadsheet-to-another.html
    Dim wF As Worksheet, wP As Worksheet
    Dim c As Range, firstaddress As String, nr As Long
    Application.ScreenUpdating = False
    Set wF = Worksheets("Full Report")
    Set wP = Worksheets("Priorities")
    nr = 8
    With wF.Columns(4)
      Set c = .Find("Incomplete", LookIn:=xlValues, LookAt:=xlWhole)
      If Not c Is Nothing Then
        firstaddress = c.Address
        Do
          wF.Rows(c.Row).Copy wP.Range("A" & nr)
          nr = wP.Range("D" & Rows.Count).End(xlUp).Offset(1).Row
          Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstaddress
      End If
    End With
    wP.Activate
    Application.ScreenUpdating = True
    End Sub

    Then run the GetIncompleteV2 macro.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  8. #8
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro help to copy row from one spreadsheet to another

    Works great. One difference between this latest code and the previous code is if I run the macro twice, it copies the rows twice which is not desired. The first code would only copy the data once no matter how many times you ran the macro which is "fail safe". Is this a simple fix?

  9. #9
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,


    Please TEST this FIRST in a COPY of your workbook (always make a backup copy before trying new code, you never know what you might lose).


    
    Option Explicit
    Sub GetIncompleteV3()
    ' stanleydgromjr, 01/15/2012
    ' http://www.excelforum.com/excel-programming/809567-macro-help-to-copy-row-from-one-spreadsheet-to-another.html
    Dim wF As Worksheet, wP As Worksheet
    Dim c As Range, firstaddress As String, nr As Long, lr As Long
    Application.ScreenUpdating = False
    Set wF = Worksheets("Full Report")
    Set wP = Worksheets("Priorities")
    lr = wP.Cells(Rows.Count, "D").End(xlUp).Row
    If lr > 7 Then wP.Range("A8:J" & lr).Clear
    nr = 8
    With wF.Columns(4)
      Set c = .Find("Incomplete", LookIn:=xlValues, LookAt:=xlWhole)
      If Not c Is Nothing Then
        firstaddress = c.Address
        Do
          wF.Rows(c.Row).Copy wP.Range("A" & nr)
          nr = wP.Range("D" & Rows.Count).End(xlUp).Offset(1).Row
          Set c = .FindNext(c)
        Loop While Not c Is Nothing And c.Address <> firstaddress
      End If
    End With
    wP.Activate
    Application.ScreenUpdating = True
    End Sub

    Then run the GetIncompleteV3 macro.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  10. #10
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro help to copy row from one spreadsheet to another

    Awesome. Than man!

  11. #11
    Registered User
    Join Date
    09-02-2010
    Location
    singapore
    MS-Off Ver
    Excel 2003
    Posts
    75

    Re: Macro help to copy row from one spreadsheet to another

    Hi Stanley,

    Could you please help to add in the explanation beside the code?
    This case is quite similar with mine. So I would like to try to modify it into my worksheet.

    Thank

  12. #12
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,

    Thanks for the feedback.

    Come back anytime.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  13. #13
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    cyee,

    Forum Rules
    2. Don't post a question in the thread of another member -- start your own. If you feel it's particularly relevant, provide a link to the other thread.


    Please create your own New Post, and then send me a Private Message with a link to your own New Post, and I will be happy to assist you.

    In your own New Post:

    To get the most precise answer, it is best to upload/attach a sample workbook (sensitive data scrubbed/removed/changed) that contains an example of your raw data on one worksheet, and on another worksheet your desired results.

    The structure and data types of the sample workbook must exactly duplicate the real workbook. Include a clear and explicit explanation of your requirements.

    To attach your workbook, scroll down and click on the Go Advanced button, then scroll down and click on the Manage Attachments button.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

  14. #14
    Registered User
    Join Date
    12-24-2011
    Location
    Nashville, TN
    MS-Off Ver
    Excel 2003
    Posts
    12

    Re: Macro help to copy row from one spreadsheet to another

    Hey Stan, it's me again. Over the past week or so I've had the chance to use the Excel spreadsheet and related macro you helped me with. By and large, it works just how I want it to but there is one more tweak I'd like to do if possible. I slightly modified the last code you sent (changed name of the "trigger word") so I've attached the latest copy of my spreadsheet so we can be on the same page. There are three worksheets in this workbook ("Full Report", "Prioritized Report" and "Executive Summary"). All of the data entry is done in the "Full Report" and once completed, your macro copies all rows that have a "No" in column D to the "Prioritized Report" spreadsheet. This function is working fine. However, the first 7 rows in the "Full Report" spreadsheet are basically "header rows" that should always be copied to the "Prioritized Report" spreadsheet and then the filtered data should begin at row 8. You last modified the macro to simply begin pasting at row 8 in the "Prioritized Sheet" which is working fine, but I'm having to do a manual cut and paste of the header rows into the "Prioritized Report" and the "Executive Summary". Can you adjust the macro to copy the first seven rows of the "Full Report" into both the "Prioritized Report" and the "Executive Summary" and then the filtered data into only the "Prioritized Report" beginning at row 8? I also want to preserve the existing function that does not duplicate data in any sheets if the macro is ran more than once. Your help is greatly appreciated. Thanks, Scott.
    Last edited by sfoxbox; 01-26-2012 at 04:11 PM. Reason: Solved.

  15. #15
    Forum Guru
    Join Date
    10-10-2008
    Location
    Northeast Pennsylvania, USA
    MS-Off Ver
    Excel 2003, 2007.
    Posts
    1,462

    Re: Macro help to copy row from one spreadsheet to another

    sfoxbox,

    Can you adjust the macro to copy the first seven rows of the "Full Report" into both the "Prioritized Report" and the "Executive Summary"
    In your latest workbook, worksheet Full Report, range A1:J7, can be copied to worksheet Prioritized Report, range A1:J7.

    But, worksheet Executive Summary, at present, only displays the data from worksheet Full Report, range A1:E3.

    Do you want me to copy worksheet Full Report, range A1:J7, into worksheet Executive Summary?


    I also want to preserve the existing function that does not duplicate data in any sheets if the macro is ran more than once.
    Please explain in detail what this means.
    Have a great day,
    Stan
    stanleydgromjr
    Windows Vista Business, Excel 2003 and 2007

    If you are satisfied with the solution(s) provided, please mark your thread as Solved by clicking EDIT in your original post, click GO ADVANCED and set the PREFIX box to SOLVED.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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.2.0