VBA Copy from WB to WB, decide which sheet to copy to.

jakobt

Active Member
Joined
May 31, 2010
Messages
337
Have a workbook called WB_A (Active workbook) and a workbook: WB_B
Want to copy sheet1 (A1:currentregion) from WB_B to WB_A.

The sheet should be inserted:
If one of the sheets in WB_A is called TB* (*meaning any other character) it should be overwritten, and copied in from cell A1.

If there is no sheet called TB* then a new sheet should be inserted named "TB.

(This should be with a VBA code, as it is part of a bigger VBA code)
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
try
workbooks("wb_A.xlsx").worksheets("sheet1").usedrange.copy
For a = 1 to sheets.count
if left(sheets(a).name,2) = "TB" then
sheets(a).Range(A1").pastespecial
end if
next a
msgbox "complete"
Ravi shankar
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,637
Latest member
Ezio2866

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