メインコンテンツへスキップ

Excelのヘッダー/フッターにセル値を配置するにはどうすればよいですか?

Excelの機能を使用して、ファイルパス、ファイル名、現在の日付、またはその他の情報を含むヘッダーまたはフッターを簡単に挿入できますが、Excelのヘッダーまたはフッターとしてセル値を使用したい場合があります。 セルの内容をブックのヘッダーまたはフッターに配置するにはどうすればよいですか?

VBAコードを含むワークシートのヘッダーまたはフッターにセル値を入力します

VBAコードを含むすべてのワークシートのヘッダーまたはフッターにセル値を入力します

Kutools forExcelを使用してファイル情報をヘッダー/フッターに挿入します 良いアイデア3


現在のワークシートのヘッダーまたはフッターにセルの内容を配置する場合は、次のVBAコードが役立ちます。 次の手順に従ってください。

1。 セル値を使用してヘルダーまたはフッターを挿入するワークシートをアクティブにしてから、 Alt + F11 キー、そしてそれは開きます Microsoft Visual Basic forApplicationsウィンドウ.

2。クリック インセット > モジュール、モジュールウィンドウに次のコードを貼り付けます。

VBAコード:指定したセル値をワークシートのヘッダーに配置します

Sub HeaderFrom()
'Update 20140318
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection.Range("A1")
Set WorkRng = Application.InputBox("Range (single cell)", xTitleId, WorkRng.Address, Type:=8)
Application.ActiveSheet.PageSetup.LeftHeader = WorkRng.Range("A1").Value
End Sub

3。 次に、 F5 このコードを実行するためのキーを押すと、ダイアログがポップアップ表示され、コンテンツをヘッダーに配置するセルを選択するように通知されます。doc-insert-cell-value-to-header1

4。 そして、 OK、この指定されたセル値は、現在のワークシートの左側のヘッダーに挿入されています。 クリックするとヘッダーを表示できます File > 印刷物。 スクリーンショットを参照してください:doc-insert-cell-value-to-header1

注意:

1.セルの内容をアクティブなワークシートのフッターとして使用する場合は、次のコードを適用できます。

VBAコード:指定したセル値をワークシートのフッターに配置します

Sub FooterFrom()
'Update 20140318
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection.Range("A1")
Set WorkRng = Application.InputBox("Range (single cell)", xTitleId, WorkRng.Address, Type:=8)
Application.ActiveSheet.PageSetup.LeftFooter = WorkRng.Range("A1").Value
End Sub

2.セル値を右ヘッダー/フッターまたは中央ヘッダー/フッターに挿入するために上記のコードを適用することもできます。 左ヘッダー / 左フッター   右ヘッダー / 右フッター or センターヘッダー / センターフッター コードで。


選択したセルの内容を含むヘッダーまたはフッターを、開いているブックのすべてのワークシートに挿入したい場合があります。上記のコードを使用して、それらを何度も繰り返す必要があります。 この場合、次のVBAコードを使用すると、セルのコンテンツをブック全体のヘルダーまたはフッターに一度に追加できます。

1。 セル値を使用してヘルダーまたはフッターを挿入するワークブックをアクティブにしてから、 Alt + F11 キー、そしてそれは開きます Microsoft Visual Basic forApplicationsウィンドウ.

2に設定します。 OK をクリックします。 インセット > モジュール、次のコードをに貼り付けます モジュールウィンドウ.

VBAコード:指定したセル値をすべてのワークシートのフッターに配置します

Sub AddFooterToAll()
'Update 20140318
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection.Range("A1")
Set WorkRng = Application.InputBox("Range (single cell)", xTitleId, WorkRng.Address, Type:=8)
For Each ws In Application.ActiveWorkbook.Worksheets
    ws.PageSetup.LeftFooter = WorkRng.Range("A1").Value
Next
End Sub

3。 次に、 F5 このコードを実行するためのキーを押すと、ワークブック全体のフッターにコンテンツを配置するセルを選択するように促すダイアログが表示されます。

doc-insert-cell-value-to-header1

4。 そして、 OK、この選択されたセル値は、すべてのワークシートの左フッターに追加されています。 クリックするとフッターを表示できます File > 印刷物。 スクリーンショットを参照してください:

doc-insert-cell-value-to-header1

注意:

1.セルの内容をブック全体のヘッダーとして使用する場合は、次のコードを適用できます。

VBAコード:指定されたセル値をすべてのワークシートのヘッダーに配置します

Sub AddHeaderToAll()
'Update 20140318
Dim WorkRng As Range
On Error Resume Next
xTitleId = "KutoolsforExcel"
Set WorkRng = Application.Selection.Range("A1")
Set WorkRng = Application.InputBox("Range (single cell)", xTitleId, WorkRng.Address, Type:=8)
For Each ws In Application.ActiveWorkbook.Worksheets
    ws.PageSetup.LeftHeader = WorkRng.Range("A1").Value
Next
End Sub

2。 代替 RightHeader / Footer or CenterHeader / Footer for LeftHeader / Footer ヘッダーまたはフッターの位置を変えたい場合は、上記のコードで。


ワークシート/ワークブック名​​、ワークブックパスなどのファイラー情報をヘッダーまたはフッターに挿入する場合は、次を使用できます。 Kutools for Excelさん ワークブック情報を挿入する Kutools forExcelをインストールしている場合のユーティリティ。

Kutools for Excel, 以上で 300 便利な機能は、あなたの仕事をより簡単にします。 

無料インストール Kutools for Excel、以下のようにしてください:

1。 クリック クツールズプラス > ワークブック > ワークブック情報を挿入する。 スクリーンショットを参照してください:
ドキュメント 1

2。 の中に ワークブック情報を挿入する ダイアログで、下に挿入する必要のある情報を確認します その他の情報 セクション、およびチェック ヘッダ or フッター 好きなように。

ヒント: ヘッダーまたはフッターのXNUMXつの場所(中央、左、または右)に情報を挿入できます。
ドキュメント挿入ワークブックパス1

3。 クリック Ok。 その後、あなたは行くことができます View > ページレイアウト ヘッダーを表示します。
ドキュメント 3

[ブック情報の挿入]を使用すると、ファイル情報をセルまたはセルの範囲に挿入することもできます。 このユーティリティの詳細については、ここをクリックしてください。



ヒント。ワークブックを複数のワークブック/ pdfファイルまたはcsvファイルにすばやく分割したい場合は、Kutools forExcelを使用してみてください。 分割ワークブック 次のスクリーンショットに示すように。 30日で無制限にフル機能、 今すぐダウンロードして無料トライアルをお試しください。

ドキュメント分割ワークブック

関連記事:

Excelのセル/ヘッダーまたはフッターにファイル名またはパスを挿入するにはどうすればよいですか?

Excelでヘッダー、フッター、ヘッダー画像を挿入および削除するにはどうすればよいですか?

最高のオフィス生産性向上ツール

🤖 Kutools AI アシスタント: 以下に基づいてデータ分析に革命をもたらします。 インテリジェントな実行   |  コードを生成  |  カスタム数式の作成  |  データを分析してグラフを生成する  |  Kutools関数を呼び出す...
人気の機能: 重複を検索、強調表示、または識別する   |  空白行を削除する   |  データを失わずに列またはセルを結合する   |   数式なしのラウンド ...
スーパールックアップ: 複数の基準の VLookup    複数の値の VLookup  |   複数のシートにわたる VLookup   |   ファジールックアップ ....
詳細ドロップダウン リスト: ドロップダウンリストを素早く作成する   |  依存関係のドロップダウン リスト   |  複数選択のドロップダウンリスト ....
列マネージャー: 特定の数の列を追加する  |  列の移動  |  Toggle 非表示列の表示ステータス  |  範囲と列の比較 ...
注目の機能: グリッドフォーカス   |  デザインビュー   |   ビッグフォーミュラバー    ワークブックとシートマネージャー   |  リソースライブラリ (自動テキスト)   |  日付ピッカー   |  ワークシートを組み合わせる   |  セルの暗号化/復号化    リストごとにメールを送信する   |  スーパーフィルター   |   特殊フィルター (太字/斜体/取り消し線をフィルター...) ...
上位 15 のツールセット12 テキスト ツール (テキストを追加, 文字を削除する、...)   |   50+ チャート 種類 (ガントチャート、...)   |   40+ 実用的 (誕生日に基づいて年齢を計算する、...)   |   19 挿入 ツール (QRコードを挿入, パスから画像を挿入、...)   |   12 変換 ツール (数字から言葉へ, 通貨の換算、...)   |   7 マージ&スプリット ツール (高度な結合行, 分割セル、...)   |   ... もっと

Kutools for Excel で Excel スキルを強化し、これまでにない効率を体験してください。 Kutools for Excelは、生産性を向上させ、時間を節約するための300以上の高度な機能を提供します。  最も必要な機能を入手するにはここをクリックしてください...

説明


Officeタブは、タブ付きのインターフェイスをOfficeにもたらし、作​​業をはるかに簡単にします

  • Word、Excel、PowerPointでタブ付きの編集と読み取りを有効にする、パブリッシャー、アクセス、Visioおよびプロジェクト。
  • 新しいウィンドウではなく、同じウィンドウの新しいタブで複数のドキュメントを開いて作成します。
  • 生産性を 50% 向上させ、毎日何百回もマウス クリックを減らすことができます!
Comments (9)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
This doesn't appear to make a dynamic link, i.e., the value entered into the header doesn't change when the value of the cell does. So what is the purpose of the VBA code, when a copy/paste will do the same?
This comment was minimized by the moderator on the site
Hello, Neil,
If you want to link the cell value to the header or footer dynamically, please apply the following VBA code:

Note: You should insert the code into the sheet code not the normal Module.
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim WorkRng As Range
Dim xStR As String
On Error Resume Next
xStR = "A1" '
Set WorkRng = Intersect(Application.ActiveSheet.Range("A1"), Target)
If WorkRng Is Nothing Then Exit Sub
Application.ActiveSheet.PageSetup.RightHeader = WorkRng.Range("A1").Value
End Sub


Please have a try, hope it can help you
This comment was minimized by the moderator on the site
maksudnya bagaimana?
This comment was minimized by the moderator on the site
Hi,

This appears to only work once.
What if the value of the cell changes?
Is there a way to link the cell so the header changes when the cell value changes?

I have a workbook where I have three sheets.

Sheet 1 labeled "Deletion Sheet" - Sheet we send to the warehouse with info what to palatalize for the order
Sheet 2 labeled "OA" - My order acknowledgement to the customer which pulls most of the data from the first sheet including the Order number which I need to have in my header. So I am trying to link the Header to the cell in this page with the order number (F5) which gets it's value from (C7) in the first work sheet ("Deletion Sheet")
Sheet 3 labeled "Invoice - Invoice which also pulls most of the same information from the first sheet which would also need the header to include the value (F5) of this sheet taken from (C7) in "Deletion Sheet"
This comment was minimized by the moderator on the site
When using your "VBA code: put a specified cell value in header of all worksheets", I would like the value placed to be formatted: Tahoma, bold, in font size 12.
How can this be added to your code?
This comment was minimized by the moderator on the site
Hi There, Is there a way that you can add a cell value which takes account of applied filters? For example... A1 = Monday A2 = Tuesday A3 = Wednesday. Using the VBA code to display cell A1 will work initially, but once I apply a filter on days of the week, the "top" cell value is no longer A1. Is there a way to pick up the variable? Many thanks,
This comment was minimized by the moderator on the site
I want to insert four cells in header.This VB is only for one cell. How can I do it. Thanks
This comment was minimized by the moderator on the site
You can try Concatenating the value of rht four cells into a single cell and then use the single cell as the header.
This comment was minimized by the moderator on the site
I needed to insert an active payroll date range into multiple sheets. The user opens the Payroll Date sheet, enters the date range and before she prints it updates all the sheets in the workbook. Here is how I am able to insert multiple cells into the range with a bit less code 2010 compatible: Private Sub Workbook_BeforePrint(Cancel As Boolean) Dim WorkRng As Range On Error Resume Next For Each ws In Application.ActiveWorkbook.Worksheets ws.PageSetup.RightHeader = Range("'Payroll Date'!A1").Value & vbCr & Range("'Payroll Date'!A2").Value Next End Sub
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations