khalid79m
09-08-2009, 04:13 AM
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A3") <> "" Then
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Intersect(Cells.SpecialCells(xlCellTypeAllValidation), Union(Columns(47), Columns(48), Columns(53), Columns(54), Columns(59), Columns(60), Columns(65), Columns(66), Columns(70), Columns(71)))
'rngDV.Select
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Target.Value = "" 'optional line depending on what you want to happen if Delete is pressed or an empty string is chosen
Else
Target.Value = oldVal & ", " & newVal
Target.Columns.AutoFit
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End If
End Sub
The above code is fine and I dont want to change it, all it does is allow multiple entries into 1 cell.
I need to write another bit of code which i have no idea how to do , this code needs to clearcontents within the same row if a value changes
eg in
AR7 changes i need it to clear contents in AS7 , AT7, AU7, AU8.
also if
AS7 changes i need to clear contetns in AT7 , AU7, AU8
In the example i have used row 7 but it could be any row from 3 to the lastrow od data.
Any help is appreicated.. Im at a complete dead end... :help
Private Sub Worksheet_Change(ByVal Target As Range)
If Range("A3") <> "" Then
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Intersect(Cells.SpecialCells(xlCellTypeAllValidation), Union(Columns(47), Columns(48), Columns(53), Columns(54), Columns(59), Columns(60), Columns(65), Columns(66), Columns(70), Columns(71)))
'rngDV.Select
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Target.Value = "" 'optional line depending on what you want to happen if Delete is pressed or an empty string is chosen
Else
Target.Value = oldVal & ", " & newVal
Target.Columns.AutoFit
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End If
End Sub
The above code is fine and I dont want to change it, all it does is allow multiple entries into 1 cell.
I need to write another bit of code which i have no idea how to do , this code needs to clearcontents within the same row if a value changes
eg in
AR7 changes i need it to clear contents in AS7 , AT7, AU7, AU8.
also if
AS7 changes i need to clear contetns in AT7 , AU7, AU8
In the example i have used row 7 but it could be any row from 3 to the lastrow od data.
Any help is appreicated.. Im at a complete dead end... :help