Copy range from worksheet to worksheet

Robandemmy

Board Regular
Joined
Jul 16, 2018
Messages
65
Hello,

I am looking for a way to copy a cell range P:T from row 8:200 if populated on one worksheet named “OTV” and paste it in worksheet “Routings” starting in cell A1 while keeping the formatting of the “Routings” worksheet. There are also 6 other tabs that I would like to copy as well and paste sequentially after the “OTV” paste.

Is this possible?

Thanks, I appreciate any help!
 
Did you change the sheet names in the code on post#27?
If so did you make the same changes to the code in post#29?
 
Upvote 0

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
My bad, some tab names were edited. Now I get:

OTV 143
269_NK 104
Extrusion(Profiled) 101
Extrusion(Profiled) CPX 102
Calendering (Flat) 100
Tringles 56
Cutter 50
Complexing 29
Finishing 50
Confection 50
Curing_OGen 101
 
Upvote 0
With the corrected sheet names does this now work
Code:
Sub copyData()
   Dim Lr As Long
   Dim i As Long
   Dim ary As Variant
   
   ary = Array("OTV", "269_NK", "Extrusion(Profiled)", "Extrusion(Profiled) CPX", "Calendering (Flat)", "Tringles", "Cutter", "Complexing", "Finishing", "Confection", "Curing_OGen")
   For i = 0 To UBound(ary)

      With Sheets(ary(i))
         Lr = .Range("P" & Rows.Count).End(xlUp).Row
         Sheets("Routings").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Lr - 7, 5).Value = .Range("P8:T" & Lr).Value
      End With
   Next i
End Sub
 
Upvote 0
If you run this what does the message box say
Code:
Sub Chk()
MsgBox Sheets("Routings").Range("A" & Rows.Count).End(xlUp).Offset(1).Row
End Sub
 
Upvote 0
That is the last row of data on the Routings sheet.
Does that make sense?
 
Upvote 0
Ok, in that case as you don't want col R add the line in blue
Code:
Sub copyData()
   Dim Lr As Long
   Dim i As Long
   Dim ary As Variant
   
   ary = Array("OTV", "269_NK", "Extrusion(Profiled)", "Extrusion(Profiled) CPX", "Calendering (Flat)", "Tringles", "Cutter", "Complexing", "Finishing", "Confection", "Curing_OGen")
   For i = 0 To UBound(ary)

      With Sheets(ary(i))
         Lr = .Range("P" & Rows.Count).End(xlUp).Row
         Sheets("Routings").Range("A" & Rows.Count).End(xlUp).Offset(1).Resize(Lr - 7, 5).Value = .Range("P8:T" & Lr).Value
      End With
   Next i
[COLOR=#0000ff]   Sheets("Routings").Columns(3).Delete[/COLOR]
End Sub
 
Upvote 0
That works great! I can always remove them after the fact but is there something that I could add to only have cells with values be copied? Most cells are formula driven and are blank unless the Q column is poopulated
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,373
Members
449,155
Latest member
ravioli44

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