Copy/Paste/Mirror A Row Into A Specific Sheet Depending on Dropdown List

ghostish

New Member
Joined
Sep 12, 2022
Messages
3
Office Version
  1. 2021
  2. 2019
  3. 2016
Platform
  1. Windows
Okay -- I've been scouring the internet including these forums to try to figure this out, but I just couldn't get exactly what I was looking for.

I'm new to VBA, so reading code that I've found and attempting to change it based on my needs hasn't worked out very well for me. I'm working on a budget and what I'd like to do is copy/paste or mirror a specific row onto another sheet depending on a dropdown list.

My dropdown list is in the F column and depending on what I pick from it, I want the row from column A through C to be copied/pasted or just mirrored onto a different sheet.

So for example, let's say there's a transaction that I want categorized under "Pets", I want that single row, columns A - C, to be c/p or mirrored onto the next empty line on my "Pets" sheet.

1663039622707.png
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
So I've found a solution that kind of works, but not exactly to the way I need it to:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets
        If ws.Name <> "Bank of America" Then
            If ws.Name = Target Then
                Target.EntireRow.Copy Sheets(ws.Name).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub

This does kind of what I need it to, but I don't want to copy the entire row. I just want to copy a single row, columns A through C. I know it has to do with this line:
VBA Code:
Target.EntireRow.Copy Sheets(ws.Name).Cells(Rows.Count, "A").End(xlUp).Offset(1, 0)
But I'm not entirely sure how to change "EntireRow" to the select singular row, only copying columns A through C.
 
Upvote 0
Figured it out!

For those wondering, this is what I came up with:
Rich (BB code):
Private Sub Worksheet_Change(ByVal Target As Range)
    If Intersect(Target, Range("F:F")) Is Nothing Then Exit Sub
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    For Each ws In Sheets
        If ws.Name <> "SHEETNAMEWHERECODEISPOSTED" Then
            If ws.Name = Target Then
                Range(Cells(Target.Row, "A"), Cells(Target.Row, "C")).Copy Sheets(ws.Name).Cells(Sheets(ws.Name).Rows.Count, "A").End(xlUp).Offset(1, 0)
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub

The underlined items are what you would change if anyone wanted to use the code!
 
Last edited by a moderator:
Upvote 0
Solution
Thanks for posting your solution.

The underlined items are what you would change if anyone wanted to use the code!
If you want to format vba code in a particular way like that, you need to use the 'RICH' code tags, not the 'VBA' code tags. I have switched them for you this time :)

1663221589022.png
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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