Once i entered the present month if column AT & AU are Not same month as in AS column
then need to delete the AT & AU Columns so the present month will appear after deleted the old month in AT & AU
Sub UpdateHeaders()
Dim ws As Worksheet
Dim headerCellAS As Range, headerCellAT As Range, headerCellAU As Range
Dim currentMonth As String
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' Replace "YourSheetName" with your actual sheet name
' Set the header cells in columns AS, AT, and AU
Set headerCellAS = ws.Range("AS1")
Set headerCellAT = ws.Range("AT1")
Set headerCellAU = ws.Range("AU1")
' Get the current month abbreviation
currentMonth = Format(Date, "mmm")
' Update the header cells with the current month
headerCellAS.Value = currentMonth & "-23 MTD (Hours)"
headerCellAT.Value = currentMonth & "-23 Hours"
headerCellAU.Value = currentMonth & "-23 ($)"
End Sub
Paste this code in a notepad file and pass the path in Invoke VBA activity and pass Method name as UpdateHeaders
Sub UpdateHeaders()
Dim ws As Worksheet
Dim headerCellAS As Range, headerCellAT As Range, headerCellAU As Range
Dim currentMonth As String
' Set the worksheet
Set ws = ThisWorkbook.Sheets("Sheet1") ' Replace "YourSheetName" with your actual sheet name
' Set the header cells in columns AS, AT, and AU
Set headerCellAS = ws.Range("AS1")
Set headerCellAT = ws.Range("AT1")
Set headerCellAU = ws.Range("AU1")
' Get the current month abbreviation
currentMonth = Format(Date, "mmm")
' Update the header cells with the current month
headerCellAS.Value = currentMonth & "-23 MTD (Hours)"
headerCellAT.Value = currentMonth & "-23 Hours"
headerCellAU.Value = currentMonth & "-23 ($)"
End Sub
Please check if it’s working as expected by doing the following steps.
In the assign activity right side put - Now.ToString(“MMM”) and in the left side create a month variable, say str_Month.
Then in the excel application scope or using the workbook activity, use Read Cell value and the cell should be “AS2”. Store in a variable, say str_ASCellValue.
In the if activity, give the condition as, not str_Month.ToUpper.Trim.Contains(str_ASCellValue.ToUpper.Trim), in then part you can do two write cell to “AT2” and the value will be str_Month+“-23” Hours and the second write cell to “AU2” and the value - str_Month+“-23” $