Copy And Paste Row If Cell Value Matches A Sheet Name

Trundlethegr8

New Member
Joined
Jan 26, 2022
Messages
6
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Good morning,

I am tracking customer expenditures. I have a Summary sheet that lists all the Customers and shows the current expenditure data. Each day I copy the data for each Customer to their individual tab and have a historical data set to reference later on. I am trying to set it up to copy rows from my Summary sheet and paste into the sheet name that matches column A. On the destination sheets, id like the existing data to be moved down one row prior to pasting the new data in row 2 so that I have a log of each entry. Row 1 has the column titles.

I am just beginning to use VBA and I currently have it set up to copy row 4 to sheet 1, row 5 to sheet 2, etc. and it definitely has its limits.

I am using Excel 2016 and on a PC.

Any help or advice would be greatly appreciated.

Thanks!
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Also, is there a way to click on a cell in column A of the Summary sheet and jump to the corresponding sheet that matches the cell value?
 
Upvote 0
Update. I found the following code after doing some more searching. This works perfectly, except I just realized I need to paste values.

Sub IncToCntySheet()

Application.ScreenUpdating = False

Dim rs As Worksheet
Set rs = Worksheets("Summary")

For r = 1 To rs.Range("A" & Rows.Count).End(xlUp).Row
wsName = rs.Cells(r, "A")

If WorksheetFunction.IsErr(Evaluate("'" & wsName & "'!A1")) = "False" Then
wr = Worksheets(wsName).Range("A" & Rows.Count).End(xlUp).Row + 1
rs.Rows(r).Copy Destination:=Worksheets(wsName).Range("A" & wr)

End If

Next r

MsgBox "Incident List Copied to Sheet"

Application.ScreenUpdating = True

End Sub
 
Upvote 0
This works perfectly, except I just realized I need to paste values.
Change this part:
VBA Code:
rs.Rows(r).Copy Destination:=Worksheets(wsName).Range("A" & wr)
to this:
VBA Code:
rs.Rows(r).Copy 
Worksheets(wsName).Range("A" & wr).PasteSpecial Paste:=xlPasteValues
 
Upvote 0
Solution
You are welcome.
Glad I was able to help!
 
Upvote 0
How would the code change if I wanted to only copy rows A through O? Sorry for the extra churn.

I'm excited to learn how to do this myself as there are just so many possibilities to make things so much easier.
 
Upvote 0
How would the code change if I wanted to only copy rows A through O? Sorry for the extra churn.

I'm excited to learn how to do this myself as there are just so many possibilities to make things so much easier.
Change this line:
VBA Code:
rs.Rows(r).Copy
to this:
VBA Code:
rs.Range(Cells(r, "A"), Cells(r, "O")).Copy
 
Upvote 0

Forum statistics

Threads
1,215,029
Messages
6,122,755
Members
449,094
Latest member
dsharae57

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