Email:      Pass:    Pass?
Close Window   
Free Ebook
Get Your Free Excel
Our Top 15 Excel Tutorials
Instant Access!
Subscribe for Free Excel tips & more!


Free Excel Forum

Macro To Select Worksheet

Forum Register
Search Excel Forum Posts, Tutorials, Macros, Tips, and More

I have a workbook with around 350 worksheets. A column in the main sheet contains a list of part numbers which correspond to the names of the worksheet tabs. When a cell on the main sheet containing a part number is selected I would like a macro to find the corresponding worksheet, move that worksheet to the end of the row of tabs and open it.

I am using excel 2007 and have limited experience of VBA and would be very grateful for any help offered.

Many thanks.

View Answers     

Similar Excel Video Tutorials

Helpful Excel Macros

Combine Multiple Workbooks into One
- This macro for Microsoft Excel allows you to combine multiple workbooks and worksheets into one new workbook and workshe
Delete All Chart Sheets in Excel - Only Chart Sheets are Deleted - Not Embedded Charts
- Delete all chart sheets and tabs in Excel using this macro. This will only delete the charts and graphs that are in the
Excel Macro that Searches Entire Workbook and Returns All Matches
- This is the ultimate Lookup Macro for Excel. It will search every worksheet in the workbook and return all of the mat
Sort Worksheet Tabs - Ascending or Descending Order
- This macro will sort all of the worksheets in the current workbook. It can sort in ascending or descending order. This
Name Worksheets Based on Cell Contents
- This macro allows you to have your worksheets named by whatever is in a particular cell within a worksheet. This means

Similar Topics

Hi Everyone,

I'm struggling to come up with a vba macro that does the following. Any help is appreciated.

I want the macro to auto generate new worksheets and copy a template onto that worksheet.

The "main" worksheet will have Column 1 and consists of part numbers, column 2 will consist of type (it will be scroll down with limited selections).

I will generate template worksheets in the same workbook. (template1,template2,template3....)

On the click of a button, it will auto generate worksheets based off column 1 (a worksheet per part number and rename that worksheet to that part number) and will either copy template1, template2,template3... depending on what is selected in column 2.

Thank you for the help. I hope it is not too complex or hard.

My OS is XP with office 2007.


I have a pretty easy question, but I am unable to get it to work and I am having a brain fart. I have an example worksheet attached and I am trying to do the following:

Search each tab of the worksheet and post the result on the Master tab if the part number is on the other tabs. My main spreadsheet has 20 tabs and around 4,000 lines.

ex. Master tab
Part# PO45W
I need to know if it comes up on the other tabs with a way to signify(true/false).

I tried this, but I am having an error:
=MATCH(A2,Sheet2:Sheet3!$A$2:$A$9, 0)
Spreadsheet Here

Thanks for looking.

Hi guys,

New to the forum and thought I'd sign up as I'm learning VB atm and trying to program my own macros. One macro that I haven't been able to code is for a report I do in my job.

Basically I receive a report (in 1 workbook) with numerous tabs for each department e.g. Finance, HR, Marketing. What my job to do is to save the file into several different workbooks, such as Overall Finance (which would include a few tabs from the main file).

I coded a macro in which it would go through the main file and delete the tabs which were not needed (leaving me with the workbook I needed, but I would need to save it and not overwrite the main file). I thought it would be easier if I could get a macro to just transfer the tabs to a new workbook, instead of deleting them..

The pseudocode would be something like this (Overall HR example):

set variables
open main workbook (not really required - workbook1)
open secondary workbook (for the tabs to be transferred to)
save secondary workbook (workbook2)
for each worksheet in workbook1
if = 'hr' then copy tab to workbook2
if = 'people management' then copy tab to workbook2
next sheet

The main problem I have is the 2 if statements in the for loop. For some reason when the macro finds the people mgmt tab (after hr) it overwrites the newly copied hr tab in workbook2.

I hope I have explained it well


Hi All,

I have a worksheet with over 100 tabs. In 1st (main) tab in column E I have got some names like:

1. Sam
2. Martha

In the following tabs I have got the details of these names.

The Tab names are 1st Main Tab: Name
Following Tabs: Martha, Sam etc.... (same as the names given in Column E of main tab)

What I want now is to put hyperlinks in main tab in column D (with Hyperlink Name as "Click Here") and upon clicking the hyperlink user should be able to go to that name tab.

Can anybody please help me to get this macro?

PS: Not every name has got a specific tab for it so macro should compare the name in Column E of main tab and tab name 1st and after that it should provide the hyperlink.

Hope I have made myself clear here. Please revert in case of any questions.

Thanks in advance for your all help!!!!

How do I create a vlookup function within a worksheet to differ between two values.

For example.

I have a workbook setup with a main worksheet listing all the part names and part numbers I buy.

Separate worksheet will contains Each suppliers pricing for the same parts.

I have named the ranges in supplier worksheets that I would like to use in the vlookup tables.

If I am using the Part number as the main lookup reference, how do I differ between the packaging with my lookup function?

If you open the attachment, you'll notice that the part name and part numbers are the same, but the package size is Bag and Box.

When you run vlookup formula, it never finds the correct Box price from Supplier A and Supplier B's pricing worksheet for the box price.

How do I fix that?

This seems like it should be so easy . . . but I can't figure it out.

I need to have a worksheet (Main Worksheet) that combines information from several different worksheet (Sub Worksheet 1, Subworksheet 2, Subworksheet 3, etc.) in the same workbook. The Sub worksheets are set up exactly the same . . . Now, in the Main Worksheet, I need in Cell C7 the information from Sub Worksheet 1 Cell E10 THEN in Cell D7 of Main Worksheet I need to offset Sub Worksheet 1 Cell E10 7 (seven) columns. I need to continue the offset in Main Worksheet 7 columns.

In other words, I need to find a way to automatically tell Excel to do the following:

Main Worksheet C7 = Sub Worksheet 1 Cell E10
Main Worksheet D7 = Sub Worksheet 1 Cell E17
Main Worksheet E7 = Sub Worksheet 1 Cell E24
Main Worksheet F7 = Sub Worksheet 1 Cell E31

Also, since I won't be updating this weekly, and the information is coming from an in-use database, this system needs to be (if possible) usable by novice Excel users.

Help! Help! Help!

hi all,

i'd love it if someone could show off their excel prowess on this one.

what i'm trying to do is have a workbook with multiple "common"
worksheets and one main worksheet. on the main worksheet i want to
have a drop-down menu where you select which common worksheet you want
to pull data from to populate the main worksheet.

the common worksheets will always be the exact same structure and will
contain a weeks worth of data. every week i want to "move and copy" a
common worksheet so that i have one worksheet for evey week. i don't
want to have to make a million worksheets at the inception of the

what i think will be the tricky part is having the drop-down menu
automatically update so at any point in time i would be able to select
any common worksheet available.

ready to learn...


I will try to explain what I am trying to accomplish, and hope that it makes sense. I have created an appointment schedule spreadsheet. Once I get the spreadsheet running smoothly, I would like to create a worksheet for every day of the year that we are open. I have decided to have one main folder with 26 subfolders in it. In each of those 26 subfolders, there will be one workbook with 12 worksheets in it. That will be two weeks worth of appointments as we are open Mon-Sat. Of course I want to name the worksheet tabs at the bottom of the workbook according to the appropriate calendar date. Then there is also a cell at the top of each page that also has the date, the same as the date on the tab. Just wondering if there is a simple way to create a macro to rename all these worksheet tabs, or if I have to physically open up each workbook, and rename all the worksheet tabs according to the calendar date. Then once the worksheet tab is named, can you make it automatically put the same date into Cell A1?

Thank you to anyone who would like to take the time to help me out with this challenging task.

Excel 2007 - I currently have a sheet "Main" that contains many buttons for selecting reports, data entry userforms, etc. When the user selects one of these buttons the appropriate worksheet is unhidden and becomes the active worksheet. Each worksheet contains an "Exit" button with a macro to return to the main menu and also hides the active sheet again.

Question 1: Is there a way to force the user to only be able to use the "Exit" button to go back to the main menu? I do not want them to be able to use the tabs across the bottom of the window.

Question 2: Is there a way remove the option of closing/saving the file except using the button on the Main page to do so? My desire is to always have the file on the Main page when the file is closed/opened.

I have a Field B5, on numerous worksheets in a workbook.
What I would like to do is create a main worksheet, that has a list in column A of all the worksheets in the book (excluding the main worksheet that was just created as a result of the macros), and its corresponding B5 data point in Column B.

In the sample workbook, I call my main worksheet "New Sheet".

Would appreciate any help. I assume this is a loop?. The number of worksheets vary and can range between 1 to greater than 200.

Thank You.

Hey all, got a doozie for ya!

I have several worksheets with different numbers of tabs, and all of the tabs are out of alphabetical order. Is there a macro that anyone can toss together that will put them in ascending order? I was thinking of creating a helper worksheet, storing each worksheet name on the sheet, sorting the names, then reorder the worksheets based on the order of the names.

Any other ideas?

Some what of a difficult one here guys

I have a list of data which is automatically imported from a database using MS Query

What I would like to do is create a unique list from the names contained in this data, then paste them into a hidden sheet

The tricky part lies in the next bit, what I then need to do is create a number of sheet tabs from these names (individual sheet tabs for each name in the list), then from the data returned in the MS Query sheet, use autofilter (? Or is there a better way) to copy the data which corresponds to that person onto their sheet tab (I can do this part i think)

The main element which is causing me trouble is creating the individual sheet tabs, which correspond to the names created from the unique values which are driven from the query data

Any help much appreciated


I would like some help creating a master sheet of rolled up information.

I have a workbook with 5 tabs with the following column headers: Part number, price, quantity with 220 rows. I would like to create a master sheet that would place all selected part numbers on the master sheet without blank rows from tabs 1-5 transferred on the main sheet. Currently I have to delete all empty rows to get it done to 20 to 25 rows which is normal size. This sheet has all totals on 1 page for printing.

Any help would be great.


Hi guys,

I have a workbook, that contains lots of worksheets. the worksheet names are number based they can be anything from 00001 to 99999..


Sub SplitSheets() 
Dim W As Worksheet 
For Each W In Worksheets 
W.SaveAs ActiveWorkbook.Path & "/" & W.Name 
Next W 
End Sub

the code above, saves each worksheet as a new document with the worksheets name.

but what i want it to do, is instead of saving each worksheet as a different file, i want it to look at a list in excel and match the numbers to a name and save it all in one workbook. So one workbook might contain 5 worksheets or another one might contain three and i want it saved as the persons name.

so for example if main.xls contains five tabs which have the tabs named:

I want person a to have 11111 and 33333 and person b to have 22222, 44444, 55555

person a's file called apa.xls and person b's as apb.xls (just an example)

and in another excel spreadsheet, it will contain 10 columns, column 1 = name and then column 2 -10 contains number sheets required..

hope that makes sence :S

thank you in advance

Hi ,
I'm using Excel 2007.
I have a workbook with many tabs (worksheets)
Each tab is named using my client's name.
So along the bottom of my workbook, i have tabs named something like
Aaron Bill John Tim


each worksheet looks basically the same
it has a cell d84 which has a dollar amount in it
it has a cell d85 which has a dollar amount in it

i want to make a new worksheet now, has column A B and C and D at the top
Column A will list each sheet name i have
Column B will list d84 from each of those corresponding sheet names
Column C will list d85 from each of those corresponding sheet names
Column D will show the result of d85-d84 all the way downn

and so on, and so on... for however many sheets i have

Thanks so much in advance for any help on this

I dunno if there's a macro that can do this... or what?
Just looking to do it automatically or as automatically as possible

= Aaron

I have a spreadsheet with 3 worksheets inside of it. The first worksheet is the main body with all the information on it. Mainly names, address, phone numbers, etc.

The other worksheets get some of the information from the first worksheet to create its own information for different departments in my office.

When i need to remove a row from the main worksheet, (i.e. a person leaves the company) i delete this row which then moves all other rows below up, but then on the other worksheets where the information was used in the formula i now get this error, because the information is gone!!!

I want this information gone, so i want the other worksheets to just delete this formula and move everything up like the first worksheet.

What is confusing is when i add a row to the main worksheet it adds it to all the other sheets in the correct order and adjust all the fomuals for the new cells on the main sheet, why then cannot it remove this when one is delelted?????

Please help. Excel 2003


Hey All,

I have an excel workbook which contains various company financial reports in different worksheets.

I have a data validation list on the main page which allows me to choose a company based on the names of all the different work sheets in cell B2 (This list is created when the workbook is opened).

What I want to be able to do is take the value from cell B2, go to the relevant excel worksheet and copy all the information from column A for rows 8 to 50

For example:

From the dropdown box in cell B2, company ABC is selected.

I then want the VBA code (on change) to go to worksheet ABC, select rows 8 to 50 of column A and then past them onto the main sheet in rows 8 to 50.

I'm struggling at the moment trying to get the cell value into an object in the code:


 'Worksheets("Main").Range("A8:A50").Value = Worksheets(ABC).Range("A8:A50").Value

If you like these VB formatting tags please consider sponsoring me in support of injured Royal Marines

I need the ABC here to be variable based on what is chosen from the list


is there any way that i can adjust this code so that if there are not enough worksheets in my workbook to support my list that more worksheets will be made and renamed? Specifically I would like to copy the first worksheet and then rename it based on my list. also... If I have more worksheets than my list requires it can delete unused worksheets?

Sub NameSheets()
Dim i As Long
Dim ws As Worksheet
i = 1
For Each ws In ActiveWorkbook.Worksheets
If ws.Name "Sheet Names" Then ws.Name = Sheets("Sheet Names").Cells(i, 1)
i = i + 1
Next ws
End Sub

I have a list on "Sheet Names" that changes the tab names on each sheet when i run the macro

I want to open a workbook, showing me a MAIN page.
I want that to have 2 worksheet tabs, labeled A and B.

If someone clicks on the "A" worksheet, they will then see another workbook (or in the same workbook) that has it's own worksheet tabs, labeled A1 and A2.

Is this possible in Excel?

If the picture doesn't work then just try this link:


Hi, I am using Excel 2003, I have 30 tabs in a workbook. Each worksheet has 200 names or more in a list. I am going to use CONSOLIDATE to move all the data to one worksheet, but before I do I need to make sure that the name on line 1 sheet 1 is the same name on line 1 sheet 2 all the way through all the 30 tabs. I tried sorting but some worksheets are longer than others. Can I use the ROW Function in some way to check that the name "Dog" which appears on line 5 sheet 1 is also on line 5 Sheet 2, Line 5 Sheet 3 ect....?


This is what i want to do.

Worksheet name = Main
This contains name of 20 people say u1 u2 etc..

When the workbook opens all 20 worksheets must be hidden automatically except for the "Main" worksheet which contains buttons which have names of 20 people.

Now, when i click on button u1 the u1 worksheet must open and prompt u1 for password. (say password = "p1").
User can enter data in that worksheet and then select a macro to email me the worksheet (i know the part how to email the workbook).

how do i go about writing the code and creating buttons etc.
Can someone please assist asap.
If you can make a file and attach that will be even better so i can go thru the code and learn how its done.
Thanks a lot.



I'm looking for a way to show the worksheets (tabs) on top of the (main)worksheet.
I saw a spreadsheet where you have the tabs on top like in an archive-system. The highlighted sheet is in front and the other tabs are in the background (but still visible).

Does anyone know how to do this??

( is not the solution!)

I have a thousand names on a column, and I have a several worksheet tabs as locations, such as CA, AZ, TX, and NY.

All names goes to main worksheet, show like this

apitchford 10 100 123
bkishpaugh 9 211 123
blee 14 234 111
cbonny 21 125 412

I need to pull a specific name, example, name = blee, move that name with all data on that row into TX.

I will need to set as automatically, becuase the names add and delete on the main worksheet, and will auto update those tab worksheets. (make sense?)

I have tried INDEX and MATCH, but they keep putting one data in, not all data.

I will be greatly appreciated. Thanks.


I am trying to find out if it's possible to sort the worksheet tabs in an Excel workbook by a master sheet list so that if it is sorted differently, I can run a macro and have it resort the tabs accordingly.

I have a tab labeled "SheetList" that contains a column with a Location ID, which is also the tab names, and a second column with a Division (Central, Eastern, Southern, Western).

Currently the tabs are in numerical order by Location ID. I would like to create a macro that I could run after resorting by Division and Location ID so that the tabs would resort in order by newly sorted Location ID column.

I have a mock up spreadsheet if needed.

Thanks in advance for any help.


Could some kind person assist with this?

Main data on a range is split by macro into several worksheets and each
worksheet get named as the result of the filtered split (i.e. if column A of
main data is entered with various rows cat dog rat there will be worksheets
called cat dog rat containing original rows from main data
If say another data line is out into Main data sheet with column A cell
called Monkey a further running of the macro is needed that adds another
worksheet called Monkey and so on.

It is required, as next step, to total each of the worksheets putting a
double underlined total box with light grey shading .

Then open another worksheet called summary that lists each total row from
each of these worksheets with that all totalled.

It is beyond my experience but would appreciate some code in order I might
make it an example to then by trial and error learn to adapt my recording of
macro's as a beginner.

Your help or ideas is appreciated greatly.