Macro Changes Header/Footer To All Worksheets
I'm looking for a macro or VBA code that can copy the header/footer and apply them to other worksheets. I have found code to copy to all worksheets but I only want the next two worksheets to have the copied header/footer and not copy to all the worksheets.
I have 6 worksheets the first 3 are schedules, the only thing that will be changed in the header/footer will be work periods. example 12/20/09-01/20/10, all other info will be the same. Is there another way to change the dates without having to open each one and manually changing the date.
View Complete Thread with Replies
Related Forum Messages:
Regarding Header And Footer...
Is there any way in excel 2007 to define a standard header and footer on the first sheet and use the same header and footer for all the remaining sheets within the workbook (same font and style as in first page).
Since I have around 25 sheets within the workbook i cannot do formatting and copy paste all the time. This will save my time alot.
Maintain Column Header And Footer
This may seem like an odd request for help, and there may be other options that I am unaware of but....
I am looking to maintain a top header row and a bottom footer row. The sheet is 300 rows deep and If I put a freeze pane or split, the header or footer ends up scrolling off of the viewable screen.
The header range is A1:G6 The footer range is A301:G304. I am looking for 2 sub()'s. The first will check the DATA range A7:G300 and hide all empty rows between the header and footer ranges. The worksheet will display lets say 23 rows of data if the user needs to enter data in a new row I would like them to be able to run a macro that will hide the first data row and unhide the first empty data row below the last row that is not empty (in the data range), and a second macro that would do just the reverse. If there were any hidden rows at the top of the data range, the first hidden row above the first unhidden row would be unhidden, and the last row of the data range would then become a hidden row.
In essence it would allow the user to scroll through the data range and never loose sight of the header range & footer range.
Append Date Variable To Header/footer
I'm trying to append a date variable to the end of headers for let's say 3 worksheets in a workbook. Each worksheet has a different string value, and I want to add a date variable at the end.
For example, sheet1, sheet2, and sheet3 says "Country Analysis", "Regional Analysis", and "State Analysis", respectively. I want to add the month and date to that so it would say something like "Country Analysis December 2007" for Sheet1, without hard coding it. Essentially, loop through however many worksheets and add a date variable at the end of each header on the left side.
I know how to get the date variable (format(date, "MMMM YYYY")) and the code behind the headers.
Before Printing Workbooks: Prompt For Footer/Header
Before printing ANY workbook, I want the user to have the option of adding a footer.
To start out with, here is the code I have:
Sub Workbook_BeforePrint(Cancel As Boolean)
'When you click 'Print', this module asks if you want to add a footer.
'The one it adds by default is: Path & filename, worksheet name, date.
'Unfortunately custom button text is not available, so Yes means add to
'current sheet, No means no, and Cancel means add to all sheets in workbook.
Dim sheet As Worksheet
If ActiveSheet.PageSetup.LeftFooter = "" Then 'if there isn't a footer already
answer = MsgBox("Do you want to add a footer?" & vbCrLf & "Yes - this sheet only, Cancel - all sheets", vbYesNoCancel)
This works just fine if I put it in the ThisWorkbook section of a workbook. The problem is I can't get to work for any old workbook. If I put it in personal.xls, nothing happens when the user clicks print.
Update Print Header And Footer With VBA Code
I am trying to link what is in the header and footer with information contained in certain Cells. (I eventually want to have a user form to help input the information, but one thing at a time.)
How do I go about getting the following information into code so that I can update the enclosed code?
Left Header: Client Name contained in Sheet: "Table of Contents" B:1
Variable In Footer For Print Macro
This sounds like a daft question I know but I have searched the forum but not found an answer despite finding a lot about footers. How do I include a formatted variable value in my printed footer? I have a function that gives me the file creation date and I need that in the footer but formatted 8pt Arial Bold. I have no problem inserting a formatted fixed string.
Macro - Report Header Import
I've got a basic handle on the application/use of macros, & personally use them for cleaning up data exported from a very very old as400esq application.
My problem is that i have managed to clean up all the blank data & piffle, but Im stupped by the header part of the text dump.
Heres an example;
A B C D E F
1 3 john 50 piano
4 1 Bill 25 horn
6 5 Ted 60 trumpet
3 3 Phil 71 Cello
1 1 James 83 Viola
3 2 Earnie 62 Violin
I basically want to rid the header rows from the spreadsheet & drop the header description (Header A/ Header B) into column F for all those items below until you get to the next header.
Macro To Paste Header Row
I'm trying to get my macro to paste the header row along with the data it's pulling. The code works without the ActiveSheet.Paste portion, but i want to be able to add that in somewhere. Here's the
Dim lstrw As Long, x As Long, y As Long, c As Range, fnd As String
Dim nxtrw As Long, dest As Worksheet, ws As Integer, caddress As String
Dim destwb As Workbook, srcwb As Workbook, src As Worksheet, src2 As Worksheet
Set srcwb = ActiveWorkbook
Set src = srcwb.Sheets("CUSTOMER ID")
'Change sheet name ot fit the sheet that has your list of unique ids
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
lstrw = src.Cells(Rows.Count, "a").End(xlUp).Row
For x = lstrw To 2 Step -1
fnd = src.Cells(x, 1)
Workbooks.Add.SaveAs fnd & ".xls"
Set destwb = Workbooks(fnd & ".xls")
Set dest = destwb.Sheets("sheet1")
For ws = 1 To 1
Set src2 = srcwb.Sheets(ws)
If WorksheetFunction.CountIf(src2.Range("b:b"), fnd) Then
Set c = .Find(what:=fnd, after:=.Cells(1, 1),
Macro: Export To Csv Without Header Line
I will admit I am a neophyte when it comes to VBA - I am JUST opening the book (never had to program before). I am trying to figure out how to create a VBA macro that will, with the click of the button, save the data in my worksheet (minus the header line) into a CSV file.
I can export the data I have into a CSV file the normal way, but I DONT want the header line included. And instead of manually removing it each time, Id like to just be able to export it, then send it to the DBA for integration.
Macro To Insert Formula Based On Column Header
I have to use several dozen pivot tables a day. I already use a couple of macros to do a lot of the tedious formatting, but if I could automate this it would save me a lot more time. I have been trying to both write a code and modify code written by the recorder but have not even come close to anything that works. What I want is to have a macro that searches through the column header for predefined names and if it comes across one of these names it will insert a specific formula, based on its name, in the first cell below the header. Then it will autofill to the last row and move on to searching for the next predefined header name. If that name is not found, it will move to the next predefined header name. One major problem is that the formula to insert under any specific header name is based on other columns in the table that aren't always in the same range. So, not only do I need it to search for columns to place a formula in, that formula has to search for the appropriate column to find the correct value to use in the calculation.
For example, one predefined column name would be Avg Price. The formula for that column would be (Sales/Qty Sold), but these 2 columns could be located anwhere in the table. How can I get it, once it has found a column that needs a formula, to locate the correct column/cell to get the correct value from the sales and Qty Sold columns?
Macro To Create Named Ranges Based On A Header Row.
I need a macro that can set up some named ranges using the text in the header row and the sheet name. The header row will always be in row one, but the number of columns will be dynamic. The amount of rows in the range will need to be dynamic also. To clarify, every used cell stating in row 2 in a column will be the named range with the sheetname+text in row one of the column the actual name.
I am facing problem with my footer, which is as under:
My footer should be printed at the bottom of my paper as shown above. But, as expected, when I change margins of page or even change the printing preference, like best print to draft print or like that, it goes changing like this:
or like this:
So, it become headache for me. i have to first see the print preview and then after I can go for printing. How to deal with this problem?
There should be two lines in footer: first will have _____________________________________only and the second one will have E-mail:firstname.lastname@example.org
Removing Automatic Footer
I have a spreadsheet here that automatically adds a footer to every sheet in every workbook. I have tried moving the footer repeatedly, but the second I try Print Preview or actually Print, the footer is automatically reapplied. There are no macros or any coding showing in VBA.
Force Specified Footer In Print
Need to write VBA for inserting Footer for each page based on Print command. My object is whenever any one is taking the print from this file my specific footer should get printed. The user should not be allowed to change it.
Add Footer In All Workbooks
I want a footer to appear on every Excel workbook that I open. Including the following code in ThisWorkbook of each workbook works, but I want it to work on any workbook, i.e. by including the code in ThisWorkbook of my Personal Workbook (personal.xls)
Private Sub Workbook_Open()
Dim ws As Worksheet
Application. ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
Application.StatusBar = "Changing footer in " & ws. Name
.LeftFooter = "&7Page &P of &N" & Chr(13) _
& "Path : " & ActiveWorkbook.FullName & Chr(13) _
& "Printed on &D at &T"
Set ws = Nothing
Application.StatusBar = False
However, when I include the code in Personal.xls, I receive the following error message when I open an Excel file: Run-time Error '91': Object variable or With block not set
Macro: Changing Color Of Coloumn Header Based On Rows Color
I wrote a macro to color the cell values in the rows based on their average value. For eg if the cell value is less than 0.2 Avg, they should be red color,if value is between 0.2 and 0.5 it should be yellow. This part is working fine
Now based on the color of the rows cells , need to write a macro for the header one. Logic is Coloum header should be in red colour, if in one or more number of rows cells are red. same with yellow ones. Could you please help me out in solving this with logic.
Page Layout Options.... Footer....
I need to add a footer to a worksheet.
I did it with the recorder, but its gives me WAY more than I need to know. But I cannot find in the macro, where EXACTLY, the footer is located.
[face=Courier New] With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.7)
.RightMargin = Application.InchesToPoints(0.7)
.TopMargin = Application.InchesToPoints(0.75)
.BottomMargin = Application.InchesToPoints(0.75)
.HeaderMargin = Application.InchesToPoints(0.3)
.FooterMargin = Application.InchesToPoints(0.3)
.Zoom = 84
Completing Footer From Initial Userform
We currently use Excel to make reports of data obtained in field surveys. General data is repetitive throughout report. We have a title page, general particulars (GP) page, table of contents then data table pages. Each data page has info from general particulars page. i.e project name, date, inspector etc. Right now some cells of data table pagess have formulars pointing to applicble cells on GP page.
Presently I am designing a userform to input title and GP page data. So far OK.
Question: Can I take input on userform and add to footer. Info to be added after or inserted within text already there? i.e. Surveyors Name: ?(left footer) something center and something right. What type of code needs to be added and where do I place it .
Prompt For Print Footer On Open
When a user Opens this particular Workbook I want them to put their name into an Input Box so that it appears on the Footer of each sheet. I have several Sheets in this particular Workbook. If they do not put there name in I want the workbook to close. I am having problems with the code I am using. Please see below:
Private Sub Workbook_Open()
Dim strName As String
strName = InputBox(Prompt:="Your Name Please.", _
Title:="Please Enter Your Name", Default:="Enter Name Here")
If strName = "Enter Name Here" Or _
strName = vbNullString Then
Else: strName = vbNotNullString
Worksheets("Front Page").RightFooter = strName
As you can see I still need a code after the first IF statement to close workbook. My main issue is after the else.
Add A Standard Footer To An Existing Worksheet
My company has a lengthy confidentiality footer that must be added on every worksheet of every workbook. I often receive existing worksheets where I need to add this footer. Is there a way to quickly/automatically add it without affecting the other existing page set up features (e.g. page orientation, margins, etc.)?
I've searched the forum and found something similar that was answered with a Before_Print Event - however I need to ensure this is on all worksheets, even if they are never printed.
The footer is: Confidential Use Only. Disclose and distribute only to XX employees having a legitimate business need to know. Disclosure outside of XX is prohibited without authorization.
I would like it centered in an 8 pt font with a hard return after each sentence end.
Change Font Color In Print Footer
I wrote a macro to do me page footers
.PageSetup.CenterFooter = "Page &P of &N"
.PageSetup.RightFooter = "Préparé le " & Format( Date, "dddd, dd MMMM yyyy")
it works fine, howver I would like to change the font color to a light grey, and I have no clue how to do that.
Macro: Switch Between The Two Worksheets
If I have an excel workbook open and then, select the side-by-side option to open another workbook, and I want to write a macro that will switch between the two - how can I do this? The problem is, I don't want it to switch by file names (one workbook constantly changes names), I just want it to switch between active workbook and inactive workbook.
Once I have the code to switch between active workbook and inactive workbook, how can I have my macro look at a cell and see if data is present and if so, drop down to the cell below.
Windows("Job Number Request form.xls").Activate
Windows("Backup Copy of 2007 Capex Job Log.xls").Activate
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
Macro: Selecting All Worksheets
I am currently working on a simple macro to help with formatting a spreadsheet. The number of tabs on the spreadsheet will change to reflect the number of companies I'm running reports for. But the same process is to be applied to each tab. The issue I'm facing is I don't know the appropriate code to select all tabs without specifically referencing them.
The code that I would like to apply to all tabs is as follows:
ActiveSheet.PageSetup.PrintArea = "$A$1:$J$85"
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
Apply Macro To All Worksheets
I need to run the below code on all work sheets:
On Error Resume Next
With Range("b1", Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
.Formula = "=If(CountIf(B$1:B1,B1)=1,"""",False)"
Basically I have lots of worksheets and I want to remove the duplicates in column B for each work sheet with a duplicate entry...
Macro: Hide Worksheets
I have an Excel spreadsheet from which I run a macro to open another workbook. This other workbook has multiple worksheets. The problem I have is that I never know which worksheet was left active whenever it was last saved. How do I revise my macro to open this workbook and make a specific worksheet active and hide all other worksheets?
Macro To Search All Worksheets
I've been writing a little macro to prompt a user with a form which lets them select 2 reports to open and also lets them select a month. One report contains financial data for the month and the other report contains all data for the year. So each month someone has to copy data from report 1 into report 2.
I have so far been able to:
-create form with error handling to open files
- select values from a pivot table in report 1
- search pivot table 1 (single sheet) and copy the Name and Total $ fields
what i haven't been able to do:
When i get the data from report 1 I switch to report 2. When i get to report to i need to search all the sheets in order to find a name with the original Name field from report 1 (I then have a HUGE case statement that will tell me if name = this and month = that then paste in cell $x$y). However, whenever i try to run my search across all sheets it will only find values on the sheet that is selected at the time.
I've attached my search code below, I would appreciate any help i can get as I've spent all day trying to resolve it with no luck
Dim ws As Worksheet
On Error Resume Next
For Each ws In ThisWorkbook.Sheets
' Find Function
Cells.Find(What:=TruncName, After:=ActiveCell, LookIn:=xlFormulas, _
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, _
ActiveCell.Comment.Text Text:="test" 'test to mark where the matched cells are
On Error Goto 0
Macro To Get Comments From All Worksheets
I am trying to find out if it is possible to do the following
I have an excel workbook with comments in a number of worksheets. I have created a macro so I can list the comments and the value of the cells with comments. The macro creates a new worksheet and list the comments and value this great but I can only get it to create the comments from the sheet which is active. Is there a way of getting all the comment and cell value from all the worksheet (the entire workbook)
this is the code for the macro
Application. ScreenUpdating = False
Dim commrange As Range
Dim mycell As Range
Dim curwks As Worksheet
Dim newwks As Worksheet
Dim i As Long
Set curwks = ActiveSheet
On Error Resume Next
Set commrange = curwks.Cells _
On Error Goto 0
If commrange Is Nothing Then
MsgBox "no comments found"
End If ...
Macro To Hide/Unhide Worksheets
Develop a macro that will enable me to hide or unhide worksheets.
Basically, I have a few worksheets in my workbook and I want to have a page at the front with two buttons. One for Unhide sheet and the other for Hide sheet. Once activated, I want it to give me a list of worksheets that I can click to hide or unhide (depending on the button i click).
Macro To Delete Hidden Worksheets
It would be great of I could delete all but one of the hidden worksheets. It would be perfect if I could tell the macro not to delete one of the hidden worksheets (called "Test O2 and CO2"), but if that is too difficult, then just one to delete all the hidden sheets would be fine.
Running A Macro On A List Of Worksheets
I have a workbook that contains a worksheet called CALC , in column A of this worksheet I have a list of other worksheets that I would like to run a macro on.
Would it be possible to set up some code that would select the worksheet at the top of the list, perform a macro then select the next worksheet in the list and carry out the macro on that sheet until all worksheets that appear in the list have been updated.
Macro: Create & Name New Worksheets
I have a workbook that is tracking part-time faculty appointments. Names and appointment details are entered on the first worksheet ("Entry"). I have another worksheet that pulls data from Entry to generate a summary of the salary for each appointment. Right now, this worksheet is called "Template" that needs to be copied and renamed for each appointment entered.
So, Entry could have up to 56 columns of data entered. There are nearly 100 rows of information for each entry (portrait-style for ease of printing). Columns A and B are information and will not have any entries. Column C is the starting point for the entry of appointments. Cell C5 will have the first appointment Name.
What I want is to create a macro that will copy the Template worksheet as many times as there are names entered from C5 and beyond (D5, E5, F5, etc.) When it creates each new worksheet, I want it to rename the new worksheet with the contents of row 5. For example, if "Smith, J." (without the quotes) is entered in C5, I want a copy of the worksheet Template called Smith, J.
The renaming of the sheet is important because I have a cell in Template that pulls the worksheet name, which is then referenced by cells in Template to pull the information pertaining to that appointment.
What I have seen here on Mr.Excel is a macro to rename a worksheet based on a specified cell, and I've seen something that looks like it created new worksheets, but I haven't seen the two put together like I'm looking for. I am also not that adept at the VBA, so I haven't really been able to figure out how to cobble it together myself.
- I have two worksheets: Entry and Template
- Names are entered into cells (C5, D5, E5, F5, etc.) on Entry
- I need to copy Template as many times as Names are entered and rename each new copy with that Name (also, new sheets should be generated at the end (right) of the current list of worksheets)
- The whole process can be activated by a button on Entry
Macro: Consolidate Data From 10 Worksheets To 1
I am trying to take a workbook with 10 worksheets and have the contents copied and pasted into a new worksheet without any extra blank rows onto a new spreadsheet. Does anyone know how to achieve this? The purpose is to copy the information off each of the 10 worksheets and be able to use the consolidated information for pivot tables.
- Each worksheet starts with data in cell A7 and ends at BL7
- The number of rows on each worksheet is inconsistent (e.g. one sheet ends at row 12 another at row 101)
- The columns have uniform titles and data below
Macro To Print Existing Worksheets
I'd like to create a macro that can access few existing worksheets from different workbooks and print them automatically when i press the button or select them.
Tried userform and listbox that were suggested from other thread, but that didnt work quite well since I'm not quite understand the code behind it.
Macro To Copy Data To Various Worksheets
I need a macro to copy data to various worksheets, in sheet workings, header is row 5, i have list of a/c codes in Col A, i need the macro to do autofilter col a5, and do a custom filter that begins with the following criterias, i then need the macro to copy filtered data to various worksheets, each worksheet is in the order of criteria, so CITI will be copied to CITIBANK_INTERNATIONAL etc. Target range to copy data to various sheets is A7
Array("CITI", "CHES", "EXIG.AMPS20", "EXIG.COGN20", "BNPP", "ATOH", "ABNA", "BBHA", "BBHT", _
"BONY", "CITA", "JPMT", "NTCT", "STATE")
Array("CITIBANK_INTERNATIONAL", "CHESS_ASSET_REC", "LIFE_EXIGO", "NOMINEE_EXIGO", "INTL", "MC_AIMS_to_HIPORT", _
"SMP_REC", "SMP_REC", "SMP_REC", "SMP_REC", "SMP_REC", "SMP_REC", "NORTHERN_TRUST", "NOMURA")
Running Macro On All Worksheets In A Book
I have a macro that I would like to run on every worksheet in my book (over 100 sheets wide). As it takes about 20 secs to run on each sheet, and I don't want to click from sheet to sheet, how can I make it run on every sheet in the book? And no, they aren't named sequentially, either alphabetically or numerically.
is there a function in Excel to return the number of sheets in a book?
Calculate Certain Cells On Two Different Worksheets Using VB Macro?
I have question on how to calculate the certain cells between 2 different worksheets based on the certain calculation parameters and the comparison result (the report) is put into the new worksheet on the same workbooks.
1) Worksheet1 contains: DEPTH, G1, C1, N1, D1, S1, SR1, MR1, DR1
2) Worksheet2 contains: DEPTH, G2, C2, N2, D2, S2, SR2, MR2, DR2
Expected result should be put in Worksheet3: DEPTH, G1, G2, calculation(G1 and G2), CI1, C2, calculation(C1 and C2), so on until the last columns. (find example on attached file "Test_Data.xls)
What I have done is to create a template to be filled in by copy and paste DEPTH, G1, G2 on worksheet1, DEPTH, C1, C2 on worksheet2, so on (attached file "Template_QC.xls"). Then I create a calculation macro for each of those worksheets separately to calculate the difference and color them . The calculation macro that I used is as follows: