I am new to VBA programming in excel and would like to know how to do the following (I have searched google and will post what I have tried here with sample code).
Column G, starting at G11 continuing to the end of the sheet, contains 2 values: either “Full Time” or “Part Time”.
In column S, starting at S11 continuing until the end of the sheet, our accountant will enter a Dollar value. The Accountant wants the excel cell in Column G to block/clear out any data and have a popup message saying that “You cannot edit this Cell in Column G as the employee is Part Time”.
I used this code, but it only works for Row 11. I would like this to work for every row in Column G. Do you have any pointers or tips? Thanks in advance.
I use the 2 events Change and SelectionChange
Private Sub Worksheet_Change(ByVal Target As Range)
If [$G11] = "Part Time" Then
[$S11].Interior.ColorIndex = 34
[$S11].ClearContents
[$S11].Locked = True
Else
[$S11].Interior.ColorIndex = 12
[$S11].Locked = False
End If
End Sub
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If [$G11] = "Part Time" Then
[$S11].ClearContents
[$S11].Locked = True
Else
[$S11].Locked = False
End If
End Sub
Try this out. I made some assumptions based on what you wrote, so if it doesn’t quite fit your data, let me know.