Paste Entire Row if Cell Value Matches Sheet Name - Resize(?) and Offset on Destination Sheet

WildBurrow

New Member
Joined
Apr 5, 2021
Messages
38
Office Version
  1. 365
Platform
  1. Windows
I'm having extreme difficulty figuring out how to resize (I think that is the term I'm looking for) and offset pasted information.

I'm using column ("A") from the source sheet ("Summary") to match tab names in the workbook. I found code (see below) that will copy and paste accordingly; however, I need to accomplish the following:
1) Only copy columns ("B:G") from source sheet ("Summary"); this means omitting data in column ("A").
2) Paste the data into columns ("J:O"), second row on the destination sheet.

Can anyone help me address this?

VBA Code:
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

'SOURCE:  https://www.mrexcel.com/board/threads/copy-rows-based-on-cell-value-to-match-with-tab-name.1167970/
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Ok, how about
VBA Code:
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 Evaluate("isref('" & wsName & "'!A1)") Then
    rs.Range("B" & r).Resize(, 6).Copy Worksheets(wsName).Range("J2")
 
End If

Next r

MsgBox "Incident List Copied to Sheet"

Application.ScreenUpdating = True

End Sub
 
Upvote 0
Solution
Ok, how about
VBA Code:
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 Evaluate("isref('" & wsName & "'!A1)") Then
    rs.Range("B" & r).Resize(, 6).Copy Worksheets(wsName).Range("J2")
 
End If

Next r

MsgBox "Incident List Copied to Sheet"

Application.ScreenUpdating = True

End Sub
Fluff,

That did the trick! I simply could not figure out how to address the copy range but I see that you simply chose:
VBA Code:
rs.Range("B" & r).copy 
'rather than using;
rs.Rows(r).Copy

Then, of course, the resize language, which was also vexing me. My previous attempts to alter the original code threw a slew of failures.

Thank you ever so much.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Glad to help & thanks for the feedback.
Could you help me on this question?
 
Upvote 0
@JakariKryze Please STOP duplicating your question and/or posting to other threads asking for help with yours.
 
Upvote 0

Forum statistics

Threads
1,214,649
Messages
6,120,732
Members
448,987
Latest member
marion_davis

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