copy paste from one workbook to another and find specific worksheet

RedOctoberKnight

Board Regular
Joined
Nov 16, 2015
Messages
150
Office Version
  1. 2016
Platform
  1. Windows
Good Morning.

I have a simple copy paste code from workbook to another but my question is, how do I get it to find a specific sheet based on value in C1 and paste there?

VBA Code:
Workbooks("Truck Schedule Builder.xlsm").Worksheets("SUN").Range("A2:D9").Copy _
    Workbooks("Truckschedulesduelsides.xlsm").Worksheets("Sun 4-3").Range("A2")

I want it to copy the Truck Schedule Builder worksheet and paste it into the truckschedulesduelsides workbook but find the specific sheet that has the same name as the value in C1 on original copy sheet (truck schedule builder)

Any help would be much appreciated.

Thanks,
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
How about
Excel Formula:
With Workbooks("Truck Schedule Builder.xlsm").Worksheets("SUN")
   .Range("A2:D9").Copy Workbooks("Truckschedulesduelsides.xlsm").Worksheets(.Range("C1").Text).Range("A2")
End With
 
Upvote 0
You shouldn't get that error, did you copy/paste what I suggested, or re-type it?
 
Upvote 0
You shouldn't get that error, did you copy/paste what I suggested, or re-type it?
My apologies, I forgot to copy the end with over too. Works now. Thank you so much.

Can I have it paste values only?
 
Upvote 0
How about
VBA Code:
With Workbooks("Truck Schedule Builder.xlsm").Worksheets("SUN")
   Workbooks("Truckschedulesduelsides.xlsm").Worksheets(.Range("C1").Text).Range("A2:D9").Value = .Range("A2:D9").Value
End With
 
Upvote 0
Solution
How about
VBA Code:
With Workbooks("Truck Schedule Builder.xlsm").Worksheets("SUN")
   Workbooks("Truckschedulesduelsides.xlsm").Worksheets(.Range("C1").Text).Range("A2:D9").Value = .Range("A2:D9").Value
End With
Thanks Fluff. As always very much appreciated.
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
Glad to help & thanks for the feedback.
Hey Fluff, I was wondering if you can add something to the code below?

When it pastes values to truckschedulesduelsides.xlsm, How do I get it to delete blank cells in range B5:P39 and shift up?

VBA Code:
With Workbooks("Truck Schedule Builder.xlsm").Worksheets("SUNDAY")
   Workbooks("Truckschedulesdualsides.xlsm").Worksheets(.Range("C1").Text).Range("G5:O39").Value = .Range("AA17:AI51").Value
   End With

I've tried adding the code below that I found on another thread you suggested but I cant get it to work.

VBA Code:
With Range("B5:P39")
   .Value = .Value
   .SpecialCells(xlCellTypeBlanks).Delete shift:=xlUp
End With

Thanks,
 
Upvote 0
As this is a total different question, it needs a new thread. Thanks
 
Upvote 0

Forum statistics

Threads
1,215,494
Messages
6,125,137
Members
449,207
Latest member
VictorSiwiide

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