Hi nomwich
I've modified the Code somewhat to anticipate multiple Change Events.
This has been handled, I believe
when you select a type from drop-down list (on a new record or one that's already been entered), it adds the record to the individual list, but if you happen to change it, it adds the item again to the same sheet, or another depending on what's selected
It's been handled by adding a Helper Column G to each Sheet. Notice the Formula in Column G. They are all the same EXCEPT for Master. These Column can be hidden (or the Font made white). I selected G because it's available in your Sample File...it can be anywhere.
I'm not certain all is handled because I'm not certain what this means
I need for the individual sheets to act as a filter of the master sheet
But this appears to be happening
displaying only that which applies to the sheet ('Fruit' only shows the fruit entries, if there are any to show).
Let me know of issues.
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim LR As Long
Dim c As Range, rng As Range
Dim mySheet As String, OldValue As String, OldCat As String, NewValue As String, NewCat As String
' If Not Target.Column = 5 Then Exit Sub
If Target.Row = 1 Then Exit Sub
If Target.Column = 5 Then
With Application
.ScreenUpdating = False
.EnableEvents = False
.Undo
OldValue = Target.Cells(1).Value 'store old name
.Undo
NewValue = Target.Cells.Value 'store new name
.Undo
OldCat = Target.Cells(1).Offset(0, 2).Value 'store old name
.Undo
NewCat = Target.Cells.Offset(0, 2).Value 'store new name
End With
Set rng = Sheets("Codes").Range("Name")
Set c = rng.Find(Target.Value, LookIn:=xlValues)
mySheet = c.Offset(0, 1).Value
With Sheets(mySheet)
LR = .Cells.Find("*", .Cells(.Rows.Count, .Columns.Count), SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious).Row + 1
.Cells(LR, "A").Value = Target.Offset(0, -3).Value
.Cells(LR, "B").Value = Target.Value
.Cells(LR, "C").Value = Target.Offset(0, -1).Value
.Cells(LR, "E").Value = Target.Offset(0, -4).Value
.Cells(LR, "D").Value = mySheet
End With
If Not OldValue = "" Then
Set c = rng.Find(OldValue, LookIn:=xlValues)
mySheet = c.Offset(0, 1).Value
With Sheets(mySheet)
Set c = .Columns(7).Find(OldCat, LookIn:=xlValues)
' Application.Goto c, True
.Rows(c.Row).EntireRow.Delete Shift:=xlUp
End With
End If
End If
If Target.Column = 1 Or Target.Column = 2 Or Target.Column = 4 Then
If Not IsEmpty(Cells(Target.Row, "E").Value) Then
With Application
.ScreenUpdating = False
.EnableEvents = False
.Undo
OldCat = .Cells(Target.Row, "G").Value 'store old name
.Undo
NewCat = .Cells(Target.Row, "G").Value 'store new name
End With
Set rng = Sheets("Codes").Range("Name")
Set c = rng.Find(Cells(Target.Row, "E").Value, LookIn:=xlValues)
mySheet = c.Offset(0, 1).Value
With Sheets(mySheet)
Set c = .Columns(7).Find(OldCat, LookIn:=xlValues)
.Cells(c.Row, "G").Value = NewCat
End With
End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
Bookmarks