VBA code based on tab

Leonidas75

Board Regular
Joined
May 12, 2015
Messages
52
Hello

I have 2 excel spreadsheets where spreadsheet 1 has tab names based on dates as follows:

Tab 1 = 01.11.18
Tab 2 = 02.11.18
Tab 3 = 03.11.18

Spreadsheet 2 (this is the main file) has a data tab and a receipts tab - the receipts tab has a cell reference based on a dynamic date (i.e. cell A1 = 02.11.18)

I am looking for code to basically say use the dynamic date (cell A1 = 02.11.18) in the receipts tab to go into Spreadsheet 1 and select the corresponding tab named 02.11.18 and copy the whole page back into the main file.

The next day the same process but will say use 03.11.18 and go to spreadsheet 1 and select the tab that has the identical name of 03.11.18.

Hope you can help
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
so wb1 = workbook 1 ( the one with the tabs 1,2,3)
wb2=workbook with the cell reference

Code:
dim wb1 as workbook, wb2 as workbook
dim ws2 as worksheet, ws1 as worksheet, ws as worksheet
dim str2 as string

set wb1=workbooks("your flile name here")
set wb2=workbooks("your other file name here")
set ws2=wb2.worksheets("your worksheet with the cell reference here")
set str2=ws2.cells(1,1)

set ws1=wb1.worksheets(str2)
ws1.select

that should do what you are asking.
 
Upvote 0

Forum statistics

Threads
1,214,927
Messages
6,122,309
Members
449,080
Latest member
jmsotelo

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