Automatically Copy Certain Columns of a Row to Separate Worksheet, Based on Specific Criteria

mcelmurrygal

New Member
Joined
May 4, 2016
Messages
4
Hi Everyone,

Before I begin, please keep in mind that I am very new to anything about VBA or codes - so please "dummy" it up for me when responding. I have looked at SEVERAL posts and tried a few codes suggested throughout them, but to no avail or success - so now I'm asking for specific help.

I have a workbook where we manually enter data into the main worksheet titled, "Data 2016". Column "G" in this worksheet has a drop-down for us to select a certain option to categorize the event for that row (i.e. - "Win", "Loss", "In Progress", etc.).

In the "Data 2016" worksheet - If one of us changes the selection in Column G to either "W - Won" or "L - Loss"; then the data from Columns A:G in that row is copied over to the next blank row on worksheet titled, "Win-Loss Data".

Hope I'm explaining well - could definitely use some help.
Thanks in advance!
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
So if the user selects Loss then that row of data should be copied to sheet named "L-Loss"
So what happens if the user selects "In Progress"

It would be easier if your sheets were given the same name as the value in the drop down.
For example select loss then that row is copied to sheet named "Loss"
 
Upvote 0
Hi,

So - if the user selects "In Progress" - I don't want anything to happen because the only data that needs to be copied over are the events that have a status update of "Win" or "Loss"

If it's easier, I can create 2 separate reporting worksheets (vs. having the single one titled, "Win-Loss"):
Win Debriefs
Loss Debriefs

Would that help?
 
Upvote 0
Here is a formula/ARRAY way to do this...
Assuming your data looks something like this...
A​
B​
C​
D​
E​
F​
G​
1​
Blah 1Blah 2Blah 3Blah 4Blah 5Blah 6Blah 7
2​
aa
1​
10​
100​
1000​
10000​
win
3​
bb
2​
20​
200​
2000​
20000​
loss
4​
cc
3​
30​
300​
3000​
30000​
win
5​
dd
4​
40​
400​
4000​
40000​
loss
For the extract on the next sheet...
A​
B​
C​
D​
E​
F​
G​
1​
Blah 1Blah 2Blah 3Blah 4Blah 5Blah 6Blah 7
2​
aa
1​
10​
100​
1000​
10000​
win
3​
cc
3​
30​
300​
3000​
30000​
win
4​
A2=IFERROR(INDEX(Sheet4!A:A,SMALL(IF(Sheet4!$G$2:$G$5="win",ROW(Sheet4!$A$2:$A$5)),ROWS($A$1:A1))),"")
ARRAY entered, using CTRL SHIFT ENTER, not just enter
Then copy down and across as needed
 
Upvote 0
It's OK:
Your quote:

In the "Data 2016" worksheet - If one of us changes the selection in Column G to either "W - Won" or "L - Loss"; then the data from Columns A:G in that row is copied over to the next blank row on worksheet titled, "Win-Loss Data".

So if either:
"W - Won" or "L - Loss"; then the data from Columns A:G in that row is copied over to the next blank row on worksheet titled, "Win-Loss Data".

That's what you want correct?

I can do that.
 
Upvote 0
Try this:

Now you realize the values must be exactly: "W - Won" or "L - Loss"
The spaces are important.

Your Workbook must be Macro Enabled.
To install this code:

Right-click on the sheet tab
Select View Code from the pop-up context menu
Paste the code in the VBA edit window




Code:
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Range("G:G")) Is Nothing Then
Dim Lastrow As Long
Lastrow = Sheets("Win-Loss Data").Cells(Rows.Count, "A").End(xlUp).Row + 1
    If Target.Value = "W - Won" Or Target.Value = "L - Loss" Then
        Range("A" & Target.Row & ":G" & Target.Row).Copy Destination:=Sheets("Win-Loss Data").Rows(Lastrow)
End If
End If
End Sub
 
Upvote 0
@My Aswer Is This,

Thank you so much!! It works perfectly and this is exactly what I needed!

@FDibbins - thank you for offering your alternate suggestion. I really wanted to go with the code route on this.

Thanks again to you both!
 
Upvote 0
Glad I was able to help you. Come back here to Mr. Excel next time you need additional assistance.
@My Aswer Is This,

Thank you so much!! It works perfectly and this is exactly what I needed!

@FDibbins - thank you for offering your alternate suggestion. I really wanted to go with the code route on this.

Thanks again to you both!
 
Upvote 0

Forum statistics

Threads
1,216,022
Messages
6,128,330
Members
449,442
Latest member
CaptBrownShoes

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top