Hello,
I need to execute a piece of code only when the user modifies certain columns. However
I noticed that the code runs also when those same columns across all my other worksheets get modified!!!
So I tried putting an "if" statement before the code in question so to identify if the columns that the user modifies are actually in the correct worksheet.
Here is the code:
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Dim row As Integer
Dim col As Integer
Dim Employee1 As String
Dim Employee2 As String
Dim Employee3 As String
Dim Employee4 As String
Dim Employee5 As String
Dim Employee6 As String
Dim DescCntStr As String
Dim DescStr As String
Dim FullStr As String
row = Target.row
col = Target.Column
If (Worksheets("wsName").Name = "Main") Then <<<< error in compilere here
' Look out only for description and employe's hours columns
If col = 6 Or col = 9 Or col = 10 Or col = 11 Or col = 12 Or col = 13 Or col = 14 Then
If Cells(row, 9).Value > 0 And Cells(row, 9) < 1000 Then
FullStr = " " & "(" & Cells(1, 9).Value & ", " & Cells(row, 9).Value & " Hrs" & ")"
End If
If Cells(row, 10).Value > 0 And Cells(row, 10) < 1000 Then
FullStr = FullStr & ", " & "(" & Cells(1, 10).Value & ", " & Cells(row, 10).Value & " Hrs" & ")"
End If
However at the line where I test if the current worksheet is "Main" I get an error
Does anyone know how we can test for the current worksheet name with an "if" statement?
Thank you for your help
RN
Bookmarks