Add current year in VBA concatenate formula

Serafin54

Board Regular
Joined
Apr 11, 2014
Messages
155
Office Version
  1. 2016
Platform
  1. Windows
Hello,

I have this code and want to make the 2023 dynamic so it's not having to be remembered to update as it were in this case 2 months into the new year. I have tried different combinations of Dim As and =Year(Now) but i'm hitting a roadblock. it is also possible i am doing this the most painful and primitive way possible so i am sorry if my code is butt ugly. It's makeshift and unrefined i'm sure. 😁




VBA Code:
 Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=CONCATENATE(G2,""-"",H2,""_"",J2,""_2023"",""_WDI"")"

Thanks
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Try this:
VBA Code:
Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=CONCATENATE(G2,""-"",H2,""_"",J2,""_" & Year(Date) & """,""_WDI"")"


Or this:

VBA Code:
Sub test3()
 Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=CONCATENATE(G2,""-"",H2,""_"",J2,""_"" & Year(TODAY()) & ""_WDI"")"
End Sub

Or this:

VBA Code:
Sub test4()
 Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=G2&""-""&H2&""_""&J2&""_""&YEAR(TODAY())&""_WDI"""
End Sub
 
Last edited:
Upvote 1
Solution
Try this:
VBA Code:
Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=CONCATENATE(G2,""-"",H2,""_"",J2,""_" & Year(Date) & """,""_WDI"")"


Or this:

VBA Code:
Sub test3()
 Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=CONCATENATE(G2,""-"",H2,""_"",J2,""_"" & Year(TODAY()) & ""_WDI"")"
End Sub

Or this:

VBA Code:
Sub test4()
 Range("A2").Resize(Cells(Rows.Count, "G").End(xlUp).Row - 1).Formula = "=G2&""-""&H2&""_""&J2&""_""&YEAR(TODAY())&""_WDI"""
End Sub

Thank you very much!
 
Upvote 1

Forum statistics

Threads
1,214,646
Messages
6,120,718
Members
448,986
Latest member
andreguerra

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