I am doing a tracker where I have two main tabs - "Home" and "MasterFile".
"Home" is the tab sheet where they will place the date today in cell B2 (since every month we will be updating this).
"MasterFile" is the template file.
The idea of the tool is to create two new sheets, copying the MasterFile as the new sheets with different filenames - "WFH + (date in B2 cell)"sheet and "MasterFile + (date in B2 cell)"Sheet.
People can edit the "WFH + (date in B2 cell)"sheet. Any changes made will changes the color of the cell as to reference to the "MasterFile + (date in B2 cell)"Sheet.
Example:
Cell B2 value is March 2024. Two new sheet tab will be generated - WFH March 2024 and MasterFile March2024.
How do I input the coding of "worksheet_change" in the newly added tab?
It should be added under "WFH + (date in B2 cell)"sheet every time we add new data.
Option Explicit
Sub NewData()
Dim MasterFileWk As Worksheet
Set MasterFileWk = ThisWorkbook.Sheets("MasterFile")
MasterFileWk.Copy after:=Workbooks("WFH tracker.xlsm").Sheets(Workbooks("WFH tracker.xlsm").Worksheets.Count)
ActiveSheet.Name = "MasterFile " & ThisWorkbook.Sheets("Home").Range("B2")
'second copy
MasterFileWk.Copy after:=Workbooks("WFH tracker.xlsm").Sheets(Workbooks("WFH tracker.xlsm").Worksheets.Count)
ActiveSheet.Name = "WFH " & ThisWorkbook.Sheets("Home").Range("B2")
On Error Resume Next
ThisWorkbook.Sheets("MasterFile " & ThisWorkbook.Sheets("Home").Range("B2")).Protect
End Sub
I am trying to insert the below code in the newly created *"WFH + (date in B2 cell)".
Sub Worksheet_Change(ByVal Target As Range)
Dim rngCell As Range
Dim WFHDate As Workbook
' Set WFHDate = Sheets("Home").Range("B2").Value
Set rngCell = Sheets("MasterFile " & ThisWorkbook.Sheets("Home").Range("B2").Value).Cells(Target.Row, Target.Column)
ActiveWindow.ThisWorksheets("WFH " & ThisWorkbook.Sheets("Home").Range("B2")).Select
If rngCell <> Target Then
Target.Interior.Color = RGB(181, 244, 0)
Else
If rngCell = Target Then
Target.Interior.Color = RGB(255, 255, 255)
End If
End If
End Sub
Meto refer to the associated worksheet. I'm not really sure what's going on in that Change event though.