Insert cell value into footer

nuficek

Board Regular
Joined
Jul 20, 2016
Messages
54
Office Version
  1. 365
Platform
  1. Windows
Could anybody help me please why my code to insert cell value to the footer doesn't work?

VBA Code:
Private Sub Workbook_BeforePrint(Cancel As Boolean)

Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("Sheet1")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")

            ws2.PageSetup.LeftFooter = format(ws1.Range("M3").Value, "dd-mmm-yyyy")
End Sub
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I tried your code as a normal sub and it works fine for me. Where have you placed the code?
 
Upvote 0
Where are you putting the code ?
Is M3 the correct location for the date ?
 
Upvote 0
I put it to the module. The problem is that the code doesn't start itself. So I think I've already found where the problem is. I copied the code under "Worksheet_Change" sub so when I change the value the code is triggered.
 
Upvote 0
Are you firing the code by pressing the print button...it works fine for me as is !!
If you put it under the worksheet_change code ...there is your problem !! wrong module !
 
Upvote 0
Basically there are two options, 1) by print button, 2) via excel menu. So keep both variants working I had to put it under worksheet_change and it works now with no problem.
 
Upvote 0
1) by print button, 2) via excel menu
For both options the code as you have it in the thread should go in the ThisWorkbook module no need for it to be in a worksheet_change.
 
Upvote 0
For both options the code as you have it in the thread should go in the ThisWorkbook module no need for it to be in a worksheet_change.
I tried that but it doesn't work. That's why asked here.
 
Upvote 0
Rich (BB code):
I tried that but it doesn't work
It actually does work in ThisWorkbook module, by any print selection method !
Are you calling it from worksheet_change event ?or other code ??
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,716
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top