English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Here's the problem; I need to create a macro that will pull a value from a specific cell and then insert that value in a header.
Any suggestions?

2007-08-29 09:22:17 · 2 answers · asked by Kevin K 1 in Computers & Internet Software

2 answers

Here is an an example that takes the value from Range C3 in the worksheet named Sheet1 and puts the value in the right header of Sheet1. All you would need to do is change the sheet names out to the sheets where you want them and change the cell range to what you want it. Then move that one line to whichever header you want it under. If you aren't going to do anything with the other headers and footers they don't even have to be included in the coding.

With Worksheets("Sheet1").PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = Worksheets("Sheet1"). _
Range("C3").Value
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
End With

The space and underscore represent a line of code continuation in VB programming. If you copied and pasted that exact code into an Excel macro and you had a Sheet named Sheet1, the code would work exactly as is. It works the same as if I had Range("C3").Value directly after the dot.

If you don't want to have to name the worksheet but have it do it to whichever worksheet you have active you can replace the text:

Worksheets("WorksheetName")

With:

ActiveSheet

In the coding. Everything else would stay the same.

2007-08-30 03:15:12 · answer #1 · answered by devilishblueyes 7 · 0 0

You could do it via VBA. I think it would be something along the lines of

Sub HeaderPath()
ActiveSheet.PageSetup.LeftHeader = ActiveWorkbook.~Cell Reference ~
End Sub

2007-08-29 16:30:36 · answer #2 · answered by Jeremie I 4 · 0 0

fedest.com, questions and answers