Charliebravo
New Member
- Joined
- Feb 28, 2022
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
Hi there, I would like to trigger a macro with the macro name derived from a named range of the cell changed during Worksheet_Change event. My code is not working as the error mesage say that the Macro is not available in workbook or macros is not enabled. Please see code below:
Named range of changed cell: Disc_GrowthRate1_EndDate
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim t As String
Let t = Target.Name.Name
Application.Run t
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Exampe of Macro:
Sub Disc_GrowthRate1_EndDate()
Range("Disc_GrowthRate1_EndDate").Value = WorksheetFunction.EoMonth(Range("Disc_GrowthRate1_EndDate").Value, 0)
Range("Disc_GrowthRate1_EndAge").Formula = "=LET(FY,DATEDIF(EOMONTH(C_DOB,0)+1,Disc_GrowthRate1_EndDate+1,""Y""),M,DATEDIF(EOMONTH(C_DOB,0)+1,Disc_GrowthRate1_EndDate+1,""M""),FY+(M-FY*12)/100)"
Range("Disc_GrowthRate1_EndYears").Formula = "=LET(FY,DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""Y""),M,DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""M""),FY+(M-FY*12)/100)"
Range("Disc_GrowthRate1_EndMonths").Formula = "=DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""M"")"
Range("Disc_GrowthRate1_EndDate").Borders.Color = RGB(226, 39, 38)
Range("Disc_GrowthRate1_EndAge,Disc_GrowthRate1_EndMonths,Disc_GrowthRate1_EndYears").Borders.Color = RGB(217, 217, 217)
Call Disc_GrowthRate_Macro3
End Sub
Hope anyone can help me. Thanks
Named range of changed cell: Disc_GrowthRate1_EndDate
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim t As String
Let t = Target.Name.Name
Application.Run t
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Exampe of Macro:
Sub Disc_GrowthRate1_EndDate()
Range("Disc_GrowthRate1_EndDate").Value = WorksheetFunction.EoMonth(Range("Disc_GrowthRate1_EndDate").Value, 0)
Range("Disc_GrowthRate1_EndAge").Formula = "=LET(FY,DATEDIF(EOMONTH(C_DOB,0)+1,Disc_GrowthRate1_EndDate+1,""Y""),M,DATEDIF(EOMONTH(C_DOB,0)+1,Disc_GrowthRate1_EndDate+1,""M""),FY+(M-FY*12)/100)"
Range("Disc_GrowthRate1_EndYears").Formula = "=LET(FY,DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""Y""),M,DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""M""),FY+(M-FY*12)/100)"
Range("Disc_GrowthRate1_EndMonths").Formula = "=DATEDIF(Disc_GrowthRate1_StartDate,Disc_GrowthRate1_EndDate+1,""M"")"
Range("Disc_GrowthRate1_EndDate").Borders.Color = RGB(226, 39, 38)
Range("Disc_GrowthRate1_EndAge,Disc_GrowthRate1_EndMonths,Disc_GrowthRate1_EndYears").Borders.Color = RGB(217, 217, 217)
Call Disc_GrowthRate_Macro3
End Sub
Hope anyone can help me. Thanks