Link to home
Start Free TrialLog in
Avatar of Andreamary
Andreamary

asked on

Adding a second worksheet that has same 'Copy partial row' functionality as Worksheet 1

I am working in Excel 2010. I have attached a sample file that currently copies a partial row from Worksheet 1 to Worksheet 2 based on the criteria outlined below. I need to add Worksheet 3 to this workbook, and want it to have exactly the same functionality as Worksheet 1 — if it meets the same criteria as outlined below, then a partial row is copied into Worksheet 2. So basically Worksheet 2 can be populated by both Worksheet 1 and Worksheet 3.

Criteria and desired result as per sample file attached:
If, in worksheet called "Worksheet 1":
A cell in any row in Column V: is not blank
A cell in the same row as above in Column X: = "Yes"
Then the following cells from the above row are copied and pasted, as values, into the next available blank row in "Worksheet 2", mapped as follows:
Column V value to Column A
Column W value to Column B
Column A value to Column C
Column B value to Column D
Column L value to Column E
Column M value to Column F

Further details:
If there are blank values in any of the cells being copied from Worksheet 1 or Worksheet 3, then the cell in Worksheet 2 would also show as blank.
The values are to be copied over just once into Worksheet 2.
The process would happen automatically anytime the above two conditions are met in Worksheet 1 or Worksheet 3.

Thanks,
Andrea
CopyPartialRow.xlsm
ASKER CERTIFIED SOLUTION
Avatar of Norie
Norie

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Andreamary
Andreamary

ASKER

Perfect! Thanks very much for the quick response...
The initial test of this solution worked, but runtime errors are surfacing after more than a copy of rows are copied over. Should I start a new thread, or can this be addressed in this thread? I've attached the file to illustrate what is happening.
CopyPartialRow-TwoSheetTest.xlsm
What do you mean 'more than a copy of the rows are copied over'?
I'm sorry but I really jumped the gun on closing this question when I did. :-( Please advise how to best rectify this. I'm providing a description of the errors I'm encountering in the file I attached in my previous post. I'm not an expert, so don't hesitate to ask for clarification if my explanations aren't clear. And if you feel that this should be handled as a new thread on my part, just let me know:

1. When entering "Yes" in X1 on either Worksheet 1 or Worksheet 3, run-time error 1004 triggered and line not copied to Worksheet 2 despite meeting criteria

2. Removing "Yes" from Worksheet 1 or Worksheet 3 triggers the line to be copied into Worksheet 2. We need the ability to remove "Yes" without it triggering any action.

3. Reapplying "Yes" to a line that has already been copied over to Worksheet 2 does not trigger the line to be copied over again. (We need the ability to remove "Yes" and reapply "Yes" to lines that have already been copied into Worksheet 2. Worksheet 1 and 3 are lists of chapters in a book, and the same chapter could be revised several times within one cycle, and each time it's going to be revised we copy it again into Worksheet 2.)

4. Removing "Yes" and/or reinserting "Yes" from X1 in either Worksheet 1 or Worksheet 3 triggers run-time error 1004 in Private Sub Workbook_SheetChange: the following line is highlighted in yellow:
 If Target.EntireRow.Cells(R, 22) <> "" And Target.EntireRow.Cells(R, 24) = "Yes" Then

Thanks for your patience,

Andrea
Oops, the problem is something from the old code that I should have fixed.

Try this for the code in the workbook module.
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)

    If Sh Is Sheet2 Then Exit Sub
    
    If Target.EntireRow.Cells(1, 22) <> "" And Target.EntireRow.Cells(1, 24) = "Yes" Then
        Application.EnableEvents = False
        CopyRow Target
        Application.EnableEvents = True
    End If
    
End Sub

Open in new window


I think that fixes all the points you raised but it's probably best if you check again.
All good now! I made sure to test it in several ways. Thanks so much...