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!
 
the column for the current year must already be unhidden

VBA Code:
 Dim f As Range
  With Sheets("Monthly Tracking")
    Set f = .Range("1:1").Find(Year(Date), , xlValues)
    MsgBox "Monthly Tracking VBA: Change cell from " & f.Offset(, -1).Address(0, 0) & " to " & f.Address(0, 0) & " for " & Year(Now()), vbInformation, "New Year Update 2 of 2"
  End With
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
OR
VBA Code:
With Sheets("Monthly Tracking")
MsgBox "Monthly Tracking VBA: " & .Cells(1, .UsedRange.SpecialCells(xlCellTypeVisible).Columns.Count).Value & " " & Year(Now()), vbInformation, "New Year Update 2 of 2"
End With
 
Upvote 0
Or, if the current year column isn't already unhidden,
this can unhide it too if need be
VBA Code:
Dim f As Range
  With Sheets("Monthly Tracking")
    Set f = .Range("1:1").Find(Year(Date) - 1, , xlValues)
    'f.Offset(, 1).EntireColumn.Hidden = False
    MsgBox "Monthly Tracking VBA: Change cell from " & f.Address(0, 0) & " to " & f.Offset(, 1).Address(0, 0) & " for " & Year(Now()), vbInformation, "New Year Update 2 of 2"
  End With
 
Upvote 0
Solution
As ever, thanks ever so much for your time, gents!

@Michael M - I tried your latest solution and it unfortunately happened to conflict with the same Selection_Change event that your code is reminding me about.
Edit: I also tried your first solution
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
And it returned "40 2022" which I guess is almost there (current year isn't hidden)

@NoSparks - your code works perfectly - thanks ever so much!
 
Last edited:
Upvote 0
You're welcome.
FYI: Michael M's first solution does what you asked for based on your response in post 5
 
Upvote 0

Forum statistics

Threads
1,214,985
Messages
6,122,606
Members
449,089
Latest member
Motoracer88

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