Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Excel


Macro To Perform Operations On All Worksheets In A Workbook

I need a macro that will perform a set of oprations on all worksheets in a workbook. The names and number of worksheets will not always be the same. I have found several macros that look like they will do this, but when I try to add my code they don't seem to work.

View Complete Thread with Replies

Sponsored Links:

Related Forum Messages:
Put Together A Set Of Macros That Perform Certain Operations Within A File
I'm try to put together a set of macros that perform certain operations within a file. However I've got a bit stuck on the following, and I can't see where I've gone wrong:

View Replies!   View Related
Loop Across Worksheets: Perform The Same Process To All The Worksheets In My Workbook
I'm trying to perform the same process to all the worksheets in my workbook. This is the code I have now, but it will only apply to the single active worksheet:

View Replies!   View Related
Perform Same Task On All Sheets In A Workbook
I am trying to make certain changes to the page setup on all sheets in a workbook. Here is my code but something is not working. I think I need to somehow select the next sheet because the macro is only performing the task on the active worksheet. My Visual Basic skills are somewhat limited so I'm sure this is not the most efficient way.

View Replies!   View Related
Faster Copy And Paste Operations In A Macro
To speed up copy and paste operations in a macro, I've heard that one can replace the following:


Sheet2.Range("B1:B200").Value= Sheet1.Range("A1:A200").Value
The second code should run faster as the clipboard is not used to store the copied info.

When I tried this, though, I didn't notice any improvement in macro running speed.

View Replies!   View Related
Getting A Commandbutton Macro To Do Operations On An Adjacent Worksheet
I am trying to make things easier for the next user by having one command button run the macros for the other worksheets (so they don't have to switch between worksheet)

I get "Runtime error '1004' Application-defined or object-defined error"

View Replies!   View Related
Macro To Perform Math Computation
I am looking for the easiest way for my worksheet to perform the following:

My 1st sheet (Sheet1) has columns A-C
In Column "A" there is a Cust # call it "P200"
In column "B" I have an invoice amount of $500.00
In column "C" -In this case, I need this field to calculate 15% of the amount in column "B"....and return the result of $75.00 (however, this 15% figure will vary based on data looked up in (Sheet2)

ie... in (Sheet2)

Column "A" will list all cust #'s that my company has - A1=P100, A2=P105, A3=P125, A4=P127, A5=P200 etc....

Column "B" has each respective discount amount for that customer by %... B1=10%, B2=10%, B3=12%, B4=20%, B5=15%

So the macro I need for (Sheet1- column C) will need to search "Sheet2" column "A" to find the "P200" out of the long list and then take the corresponding % amount in column "B" (in this case it's 15%) and use this figure in (Sheet 1) to perform the calc.

View Replies!   View Related
Set Macro For All Worksheets (active Workbook)
Sub display_all_false()
With Application
.DisplayGridlines = False
.DisplayHeadings = False
.DisplayOutline = False
.DisplayZeros = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False
.DisplayFormulaBar = False
.DisplayStatusBar = False
.ShowWindowsInTaskbar = False
.CommandBars("Standard").Visible = False
.CommandBars("Formatting").Visible = False
.CommandBars("Control Toolbox").Visible = False
.CommandBars("Drawing").Visible = False
End With
End Sub

But, when I run the code, seems there're run-time errors detected at these codes:
.DisplayGridlines = False
.DisplayHeadings = False
.DisplayOutline = False
.DisplayZeros = False
.DisplayVerticalScrollBar = False
.DisplayWorkbookTabs = False

1. Is there any way to correct these codes?
2. Does the bolded codes applied to ActiveWindow (Worksheet) only (eg. With ActiveWindow ...)? Can I change it to ActiveWorkbook (perhaps)?
3. Can the command menus (File Edit View Insert Format ...) be hidden also?
4. Does looping method for each worksheet

View Replies!   View Related
Reduce File Size Using Macro To Perform 500,000 Calculations
I have this formula that checks a line of values to see whether it is within the constraints of a separate list of values.


View Replies!   View Related
Reduce Macro Perform Array Of Sheet (not All Sheets)
How can I make this macro easier (smaller)? The same action is performed on an array of sheets (not all sheets).

View Replies!   View Related
Macro - Opening, Copying And Saving Workbook To Worksheets
I have been trying to create a Macro that can do the following.

Open a Excel Workbook, Copy the Worksheets that I need (ignoring ones that are not needed.), Save them in the correct location with a new folder of date and time and saving them as csv files.

I have all the elements but can't seem to get them to gel correctly.

Just wondering if anyone has anything like this that I could adapt or edit.

View Replies!   View Related
Error Handling Within Errors (macro To Create New Worksheets In The Workbook)
I am currently creating a database which involves using a macro to create new worksheets in the workbook. When the macro is run and a work sheet is being inserted, an input box asks the user for a worksheet name.

As you can imagine, the worksheet does not like it when the worksheet name input by the user, is the same as one already existing and so throws up a 1004 error.

In order to resolve this error I have included an error handling code to request the user to input a differnet worksheet name, as the one previously inserted exists.

My problem: It all works fine until the user types in an existing worksheet name twice, so once initially and again when the error handler has prompted a second attempt. On the second incorrect input a 1004 error warning is displayed.

I would like the error handler to keep repeating until a worksheet name that doesn't exist is inserted by the user. Is this possible?

My code so far:

Sub NewTrancheSheet()
Sheets("Tranche Sheet Template").Visible = True
Sheets("Tranche Sheet Template").Select

Sheets("Tranche Sheet Template").Copy Before:=Sheets(1)

Sheets("Tranche Sheet Template (2)").Select
Sheets("Tranche Sheet Template (2)").Move After:=Sheets(Sheets.Count)
Sheets("Tranche Sheet Template (2)").Select.................

View Replies!   View Related
Macro To Create Worksheet 'xxxx' And List All Worksheets In Workbook
I am after some code to create a new worksheet called 'xxxx' in my workbook, and then list all the sheets within the workbook (excluding the newly created 'xxxx' sheet.)

View Replies!   View Related
Copy Worksheets From Active Workbook To A New Workbook
I am trying to code a Macro so that i can take all the worsheets and save them as individual Workbooks. I wrote a macro that appeared to work, but, after it saves the first sheet as a workbook, i get a debug error.

MS VB Script error:
Runtime error '9':
Subscript out of range

Any advise would be greatly appreciated.

Thank you

Code is below..

Sub saveall()
For Each ws In ActiveWorkbook.Worksheets

ThisFN = "C:Documents and SettingsUserDesktop" & ws.Name & ".xls"
I = I + 1
ActiveWorkbook.SaveAs Filename:= _
ThisFN, FileFormat:=xlNormal, _
Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, _

Next ws

End Sub

View Replies!   View Related
Dates Operations
Does excel contain a format of : "number of months"?

Example : I have 3 cells
A1 : should contain the number of months (3 months)
A2 : should contain a date with this format (dd/mm/aaaa)
A3 : should contain A1+A2

View Replies!   View Related
Order Of Operations Within A Formula
I have "bashed into shape" a formula that involves 2 sets of parenthesis. After progressing beyond "#REF! or #NAME errors, Excel's automated Help suggested to add a comma, and the formula functions as wanted, I thought I was "Smart".

Later, when saving the formula to my `Formula Workbook', "Order of Operations" crossed my mind. - I think this formula is backwards, but `Excel Help' only suggested the addition of a comma? Maybe the all inclusive parenthes allowed the order to be understood?

The Formula: =AVERAGE((E56:AH56),COUNTIF(E56:AH56,">0"))

Q: Shouldn't the COUNTIF occur before the AVERAGE? Did the extra Parenthis automate the order of Operation within the Parenthis?

View Replies!   View Related
One Cell To Control 3 Operations
I need to have the contents of cell A1 (a 3 component list) control a formula in cell E1. If A1 is "add", then E1 should be B1 x D1. If A1 is "delete", then E1 should be B1 x D1 x .6, and if A1 is "delete ilo", then E1 should be B1 x D1 x (-1).

A1 B1 C1 D1 E1

list qty. list price of C1 item formula needed
( lookup)

View Replies!   View Related
Mathematical Range Operations In VBA
I'm attempting to conditionally alter specific column range values based on the variable 'tagrow'. From the example you can see that if 'tagrow' is 7 or 8, I want to divide the values in column C by 1000 and put them in column D. If tagrow was different, I will use another conditional statement with a different denominator.
In the current code, I get a type mismatch error. I have also tried dividing by an equal size column range full of 1000's, with no luck (matrix math anyone?). All I want to do is manipulate ranges!

'Initializing tagrow so we can test what train we are trending'
tagrow = Cells(12, 2).Value

'Only Propylene flows need adjustment in A and B trains, calculate everything'
If tagrow = 7 Or tagrow = 8 Then
Range("D15:D115").Value = Range("C15:C115").Value / 1000
End If

View Replies!   View Related
Nested IF Formula, Order Of Operations
I am trying to write a formula in 2003. The basic premise is below and I'm having problems getting all the senarios to work out.

E20 = Calc'ed amount
E22 = Min amount (Sometimes equals zero - No Min)
E23 = Max amount (Sometimes equals zero - No Max)
E24 = Additional amount to add


View Replies!   View Related
Multiple Copy & Paste Operations
I want to copy several separate sections on a worksheet and place these sequentially in an array, then paste these in order into another worksheet.

I have written a macro to copy and paste between the two spreadsheets, however, this is rather basic as it involves straddling between the two and performing multiple alternate copy and paste operations, as only one section can be copied at any one time.

View Replies!   View Related
Multiple Operations And Formulas In Spread Sheet
I need to create a spread sheet that in Col A has 3 variables, each of which I need to triger 1)fill of that row, 2)different formula's in different columns within that row. Is this possible in excel?

View Replies!   View Related
3 Worksheets In One Workbook
I have 3 worksheets in one workbook. I need to extract 10 random rows of information from about 193 rows in sheet 1, and post it in sheet 2 and I can't seem to find a way to make this happen correctly.

View Replies!   View Related
Match And Copy: Declare The Variables Correctly And Have The Operations Done In A Series Of Do/ Loops Or For/Nexts
I have a series of operations to carry out and, while I can do the code for each individual one, how to declare the variables correctly and have the operations done in a series of Do/ Loops or For/Nexts. Especially the declaring of named ranges as variables. Also a bit uncertain of the best way to find and coy the match. I have attached a simplified version of the workbook, with explanations on it.

Basically what I need to do is loop through a series of named ranges and then loop through the names in each, match each name with a name in a master list (with a flag as an image), add an e-mail hyperlink to that flagged name and copy both to a new cell.

View Replies!   View Related
Perform Running Total
The following code works great in selecting individual cells and forming a text string with them. What I need to do is to change this slightly andi instead of just reading the cell, have the preceding value added to the current value "(Cells (e,i)" and that new runnng total value is added to the "temp" string.

The concept is 12 cells represent Jan - Dec (numbered 1-12)
I'm trying to perform a running total; where Feb(2) = (Jan(1) + Feb(2)) and Mar(3) = Feb(2) + Mar(3).....

I tried setting x to do the running total and then passing it to "temp" but I kept getting mismatch errors, or buffer overflow errors, or out of memory errors.

Is there someone who can provide some assistance with the proper way to do this? ....

View Replies!   View Related
Copy Worksheets To New Workbook
I have a workbook containing several worksheets I want to copy to a workbook of their own and save under a specific name/password through a macro.

However, I have five difficulties:

1) I want to new workbook to contain only 1 worksheet. So, only the worksheet copied from the original workbook, and no other worksheets.

2) I want to be able to manually select the destination file for the copied workbook, however. This should be the same file for all workbooks.

3) I want the data copied from original worksheet to be ‘pasted as value’ only, so no formulas in the new workbook.

4) I want the new workbook to be read-only. Therefore I want the workbook to be /locked and password protected. So, the password should be only for altering cells, not for opening the workbook. See also point below.

5) Regarding the naming and passwording part I have made a matrix table in a worksheet named: “Rekeningen” (this worksheet is in the original workbook). This table contains three columns:

Column A, cells 40:65, contains the names of the worksheets I want to copy
Column B, cells 40:65, contains the names of the new workbooks
Column C, cells 40:65, contains the passwords of the new workbooks

So for example ....

View Replies!   View Related
Protecting Worksheets In A Workbook
I have a workbook with several worksheets in it. One worksheet for each manager. I only want the individual manager to see their individual worksheet and not those for the others. Is it possible to hide the worksheet and unhide it using an individual password, a seperate one for each manager ?

or alternativly, is it possible to hide say the columns and give each manager their own password that only allows them to unhide the columns for their worksheet. I really dont want to have to send out several seperate versions, just sending one workbook but passwording the individual worksheets within it would be ideal.

View Replies!   View Related
Merge Worksheets Into One Within Same Workbook
how to merge data from all worksheets into one new in the same workbook, see example in attach. There are 5 worksheets in the test workbook. Each worksheet has name of “Sheetx”,X=number of worksheet. Number of Row in each worksheet is uncertain, but it is always less than 35 (I will say it is “safe” range to prevent from missing data). Requirement: Vertically merge data from A1:F35 (including the “blank”) to “TEST”.

I am using Excel 2007 at office. By the way, I am NOT a excel expert, while posting your answer, could you please also explain how to do it step by step?

View Replies!   View Related
Arrange 2 Worksheets In The Same Workbook
Can you arrange 2 worksheets in the same workbook so they are side by side, like you can the way you can tile two different workbooks?

View Replies!   View Related
Several Worksheets Same Workbook Same Formulas
I use excel 2003 SP3. I've created invoices that have several (very basic), but different formulas in the last column of the worksheet. I have the same customers every month so I use the same monthly workbook for all invoices. Since each invoice has the same formulas, in the same cells, I used the SHIFT key while selecting the entire range of worksheets (invoices). After they have been selected, I entered the SUM formula in a cell so it would automatically be entered in all of the worksheets (invoices).

When I select the same cell in all the worksheets (invoices) I can see that the formula is there. However, when I enter a value that the formula should be adding, it doesn't. But if I select the cell with the formula in it, the formula shows in the formula bar. When I put my cursor at the end of the formula and hit ENTER, the formula then works. So I have to select each formula, in each cell, on every worksheet, hit ENTER, and then, if I need to change a value, I have to repeat the process. I am definitely missing something, and I'm sure it's quite obvious and simple.

View Replies!   View Related
Organizing Worksheets In A Workbook
Is there a way to sort the worksheets in a workbook after they have already been entered. My clerk put 200+ worksheets in one workbook....out of order.

View Replies!   View Related
Copy All WorkSheets To Another Workbook
Assume 2 Workbooks - the Active one and "Book2".

I mannaged to copy ALL the sheets from the ActiveWorkBook to "Book2" with the following code - but as you can see the code copies each of them AFTER the last sheet in "Book2".

Sub Copy_Sheets()
' Copy All sheets from ActiveWorkbook to "Book2.xls"
For Each SH In ActiveWorkbook.Sheets
SH.Copy After:=Workbooks("Book2").Sheets(Workbooks("Book2").Sheets.Count)
End Sub

How can I copy them to "BEFORE", lets say Sheet(1) in "Book2" ?

I tried to change the SH.Copy command to somthing that sounds logic to me, such as:

SH.Copy Before:=Workbooks("Book2.xls").Sheets(1)

but got the: "Run-time error '9' - Subscript out of range".

View Replies!   View Related
List The Worksheets In A Workbook
I have around 40 to 50 worksheets in a workbook. Is there a quick way of listing the names of all the worksheets in a single worksheet instead of typing the sheet names one by one?

View Replies!   View Related
Checkbox, To Perform Column Hide
I would like to have a checkbox that when checked displays a column and when not checked hides the column.
the Column to be hidden will be on a page titled "Totals"
the checkbox will be on a page called "Roster"
the column to be hidden will be "Totals!M"

now for the real problem
I am using Excel 2004 for Mac. Which does not have a "control toolbox"

what should i do. I tried to do a macro but all that does is run the macro when the object is clicked regardless of if you are checking or unchecking.

View Replies!   View Related
Loop Through Array And Perform Formula
trying to loop through an array, with each loop calculating a formula (VLOOKUP) for one cell based on the values of a cell in another sheet.

Not sure but I think it has something to do with looking up a text value while the loop returns a value.

Private Sub ExpandFormula()
'calculates Counttarget formula in COUNTTARGETS sheet across required range
Dim CellsDown As Long, CellsAcross As Integer
Dim i As Long, j As Integer
Dim TempArray() As String
Dim TheRange As Range
Dim CurrentValue As String

'get the dimensions
CellsDown = Worksheets("SEPARATE").Range("D9").Value
CellsAcross = Worksheets("SEPARATE").Range("E9").Value

'redimension temporary array
Redim TempArray(1 To CellsDown, 1 To CellsAcross) .....................

View Replies!   View Related
Can A Cell Contain Text And Perform Calculation?
I would like to have a cell in which there is descriptive text and the results of a calculation. For example, in row 2, I want to state the current total number of items in inventory at the top of the sheet in the center of the used cells.

Inventory Total is: SUM(A4:A64,000) as of: Date()

I can't merge cells or manipulate the text in such a way to neatly bring the text and calculation together. And there are actually 2 calculations in the example above. One to SUM the items and one to add the date.

View Replies!   View Related
Perform Vlookup Across Multiple Tables
I am wondering if there is a way of performing Vlookup across several tables? I have tried to create a formula myself based on lookup and nested vlookups, but am getting all tanlged up, especially as I need an If isna formula in there so that if there isn't a result, it displays a 0 rather than a #N/A.

See the attached. I do compeltely understand that it would be so much easier if all the data on the commission worksheet was in a simple 3 column table, but it has to be split as it is creating 3 tables. exactly what formula needs to go in cell D7 on the rates worksheet that I can drag down, which will check for those initials across all 3 tables? (The initials will only appear once on the table on the commission worksheet.

View Replies!   View Related
Perform VLookup And Hlookup At The Same Time
I was wondering is it possible to perform a VLOOKUP AND HLOOKUP in the same formulae or is there another way to perform this task. the attached example

View Replies!   View Related
Merging Multiple Worksheets Into A Workbook
I have a task to complete that requires me to extract worksheets from hundreds of workbooks and consolidate them into one "master" workbook. Out of the hundreds of workbooks, there is only one worksheet that I need to extract from each. The worksheet's name is "CostData". Once I have all the worksheets in one workbook, I will have to create buttons that will be able generate reports and charts based off the data in the worksheets. This will assist in determining cost comparisons, trends, and predictions. I am sure something like this has been done before, so can someone please help me out! Is there any code out there that can do this?

View Replies!   View Related
Averaging From Multiple Worksheets Within A Workbook
I'm trying to do some averages for a year to date "cover" sheet. Worksheet 2 is Jan, Worksheet 3 is Feb, etc..through December. Worksheet 1 is the year to date averages. My data is a formula on each worksheet in cell B22, I thought I had the function written correctly however Excel won't take it:

=AVERAGE(IF(January!B22,February!B22,March!B22,April!B22,May!B22,June!B22,July!B22,August!B22,September!B22,October!B22, November!B22,December!B220, January!B22,February!B22,March!B22,April!B22,May!B22,June!B22,July!B22,August!B22,September!B22,October!B22,November!B22 ,December!B22,""))

There are blanks,of course, until each month is filled in. Could it be because the number that is in B22 on each worksheet is the result of a formula instead of typed number

View Replies!   View Related
Search A Workbook With Multiple Worksheets
Need MACRO to search a workbook with multiple worksheets?

View Replies!   View Related
Consolidate All Worksheets Into Master Workbook
I think this needs a For Each loop, but I am stuck on how to get it accompished. In the folder I will have about 26 workbooks with all different titles, but the beggining is always the same for the workbook and the worksheet (Bldg). There will be only one ws per wb and the wb I am using to collect all of the worksheets is Final.xls. The code attached works fine, but the only way right now I know how to capture the next wb/ws is with a call.

Sub CopyAllWrksht() ....

View Replies!   View Related
Apply Code To All Worksheets In Workbook
I recorded a macro in an Excel Workbook which contains 65 worksheets (--this is something received on a quarterly basis for which I have no control). The macro is successful within the workbook created however, a new quarter's data may or maynot have some of the referenced worksheets. 64.9 Waiv - 1 may exists and the others (2, 3, 4, etc) not. The macro fails and prompts for Debug if a worksheet does not exist.

Sheets("64.9 Waiv - 1").Select
Sheets("64.9 Waiv - 2").Select
Sheets("64.9 Waiv - 3").Select
Sheets("64.9 Waiv - 4").Select
Sheets("64.9 Waiv - 5").Select
Sheets("64.9 Waiv - 6").Select
Sheets("64.9 Waiv - 7").Select
Sheets("64.9 Waiv - 8").Select
Sheets("64.9 Waiv - 9").Select
Sheets("64.9 Waiv - 10").Select

Is it possible to alter the macro to look for and only invoke the code if a worksheet past 1 were to exist?

This is what I am requesting the macro do:

Sheets("64.9 Waiv - 1").Select
ActiveWindow.FreezePanes = True
ActiveWindow.SmallScroll ToRight:=5
Range("J8").Select ...............

View Replies!   View Related
Array That Consists Of 120 Worksheets Within A Workbook
I have an array that consists of 120 worksheets within a workbook.

For example: Array(A,B,C,D,E,F,G...etc) for all the worksheets

Can I condense the array or change the format so that I do not have to list all of the worksheets every time I reference the array?

View Replies!   View Related
Copying Worksheets From Various Files To New Workbook
I have 100 files (Book1.xls through Book100.xls)

All files reside in L:MISInernal MIS

I need to open each workbook, copy Sheet1, paste to next available Sheet# in Combined.xls, close the workbook and move to the next workbook.

I have the code for copying a specific sheet from one workbook to a new workbook. But I do not have the code which would perform the above mentioned task for me and I don't have any idea for how am I going to do this without your help

I have used the Search option to find out if this question had already been answered but I could not find a solution for this specific request

View Replies!   View Related
Copy Active Worksheets Into One New Workbook
I have 16 proposals that are either hidden or visible in a proposal generator. I need to be able to copy only the visible worksheets over to a new workbook that uses a name from a cell inside the proposal generator. Then a save as prompt to force the user to save the file wherever they choose.

View Replies!   View Related
Create Separate Worksheets Within Workbook
I have a table of data with three columns. In the first column I have different values, but they can also repeat. How can I have VB look at my table and for every distinct value in the first column create a sheet with the value name and paste all the data into that same sheet?

View Replies!   View Related
Shortcut For Navigating Between 2 Worksheets In The Same Workbook
is there a shortcut for navigating between 2 worksheets in the same workbook...
for eg if i am copying some values from sheet 1 into sheet 2 of the same workbook...wat i am doing now is clicking sheet1 copying the value then clicking sheet2 and pasting the value in the cell i want.. i want some shortcut ( if its there ) like ALT+TAB which is for navigating between different open windows.

View Replies!   View Related
Copy All Worksheets Into Master Workbook
Using a Command button into my Master file, I'm looking for a code that give me an option to select an existing file that will have a variable name & path, open it and then copy all worksheets contained within it, into my Master workbook. Then close the selected file on completion.

Not sure if it's important but some of the copied worksheet names will contain copies. e.g. Apples, Apples (2), Pears, Pears (2). etc.

View Replies!   View Related
Toggle Betwen 2 Worksheets In Same Workbook
I need do now is write instructions for others to follow.

I will name sheet "Instructions" .

On my summary sheet I want to have a cell or button that can be clicked and take one to the "Instruction" sheet without the need to click on tab name.
If possible the Instruction sheet to have a similar button to return to summary sheet.

View Replies!   View Related
Organize Worksheets In A Workbook Ascending
I have the code below that will organize worksheets in a workbook ascending (1,2,3...) and would like to know how to deal with the For loop not initialized "Run-time error '92'" message that shows up at the end.

I'm teaching myself as I go and would like some light on this if you don't mind. Also would like to know if there is any 'better' way per-se to do this kind of task.

View Replies!   View Related
Compare Formula- Workbook With Two Worksheets
I have a workbook with two worksheets

worksheet a holds the following information

column a - employee number, column b - distribution number, column c - account number associated with the distribution number.

worksheet b holds the following information

column a - employee number, column b - check number, column c - distribution number, column d - account number associated with the distribution number

what I want is a statement that will do this:

in worksheet b, take the employee number and distribution number in row a and find the row in worksheet b that is the same, then compare the distribution numbers to see if they match.

View Replies!   View Related
Copyright © 2005-08, All rights reserved