I was able to sucessfully create a code that would erase the contents of other cells if they did not match up with the original one (i.e A2).
Issue
I wanted to expand this code to clear the content of more cells. Currently, it only work on A, B, and C. Do you know how I can expand it to D, E, and F
This code only works for the second row, but i need it to encompass the 2nd, 3rd, and 4th row. Any help would be awesome!
PHP Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngState As Range
Dim rngDivision As Range
Dim rngClear As Range
Dim rCell As Range
Set rngState = Intersect(Columns("A"), Target)
Set rngDivision = Intersect(Columns("B"), Target)
Application.EnableEvents = False
If Not rngState Is Nothing Then
For Each rCell In rngState.Cells
Select Case (rngClear Is Nothing)
Case True: Set rngClear = rCell.Offset(, 1).Resize(, 2)
Case Else: Set rngClear = Union(rngClear, rCell.Offset(, 1).Resize(, 2))
End Select
Next rCell
rngClear.ClearContents
Set rngClear = Nothing
End If
If Not rngDivision Is Nothing Then
For Each rCell In rngDivision.Cells
Select Case (rngClear Is Nothing)
Case True: Set rngClear = rCell.Offset(, 1)
Case Else: Set rngClear = Union(rngClear, rCell.Offset(, 1))
End Select
Next rCell
rngClear.ClearContents
Set rngClear = Nothing
End If
If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
?None of us is as good as all of us? - Ray Kroc ?Actually, I *am* a rocket scientist.? - JB (little ones count!)
Bookmarks