Automatically advance cell reference in message box each year

Ironman

Well-known Member
Joined
Jan 31, 2004
Messages
1,069
Office Version
  1. 365
Platform
  1. Windows
Hi and a Happy New Year to you!

I have this message box code
VBA Code:
MsgBox "Monthly Tracking VBA: Change cell from AN1 to AO1 for " & Year(Now()), vbInformation, "New Year Update 2 of 2"

I'd be grateful for some code that will automatically advance the cell references each year, so Jan 1 2023 shows
VBA Code:
"Monthly Tracking VBA: Change cell from AO1 to AP1 for " & Year(Now()), vbInformation, "New Year Update 2 of 2"
and so on at the start of each year.

Many thanks!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Are these references based on a last column for that row ??
VBA Code:
AO1 to AP1
 
Upvote 0
You're already using Dante's code to set f to the cell of the the current year.
so the address for the current year in that message would be f.address(0,0) and last year would be f.offset(,-1).address(0,0)
 
Upvote 0
too late to edit previous post:
and next year would be f.offset(,1).address(0,0)
 
Upvote 0
Hi Michael & Nolan, Happy New Year to you both!

@Michael M - the last visible column, which is unhidden on Jan 1 every year.
@NoSparks - many thanks, although this is a different sheet that doesn't use Dante's code.
 
Upvote 0
@Ironman Do you mean like this
VBA Code:
MsgBox "Monthly Tracking VBA: " & Cells(1, Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column) & " " & Year(Now()), vbInformation, "New Year Update 2 of 2"
 
Upvote 0
@Ironman Do you mean like this
VBA Code:
MsgBox "Monthly Tracking VBA: " & Cells(1, Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column) & " " & Year(Now()), vbInformation, "New Year Update 2 of 2"
Ah, I hadn't thought of it that way - this is a Workbook_Open event on Jan 1. What other info do you need so it will locate the next column AO1 (and AP1 etc) in the Monthly Tracking sheet to fit the message box "Monthly Tracking VBA: Change cell from AN1 to AO1 for " & Year(Now()), vbInformation, "New Year Update 2 of 2"?
 
Upvote 0
MAybe this way then...
VBA Code:
Dim lc As Integer
With Sheets("Monthly Tracking")
MsgBox "Monthly Tracking VBA: " & .Cells(1, .Cells.Find("*", , xlValues, , xlByColumns, xlPrevious).Column).Value & " " & Year(Now()), vbInformation, "New Year Update 2 of 2"
End With
 
Upvote 0
Thanks Michael - I only got a message box with "Monthly Tracking VBA: ". You're way more clued up than I am but isn't the "*" a wildcard rather than a defined starting point such as AN1?
 
Upvote 0
Sorry, I assumed that row 1 would hold the last column !
BUT, if you have data beyond the desired column in row 1 it will return that value !
Try using
VBA Code:
Dim lc As Integer
With Sheets("Monthly Tracking")
MsgBox "Monthly Tracking VBA: " & .Cells(1, .Cells(1, Columns.Count).End(xlToLeft).Column).Value & " " & Year(Now()), vbInformation, "New Year Update 2 of 2"
End With
 
Upvote 0

Forum statistics

Threads
1,215,039
Messages
6,122,802
Members
449,095
Latest member
m_smith_solihull

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