i need help using this code in another work book with different name. When I change the name of the sheet 2 to the new sheet of Table- it doent work the cells go blank and code doesn;t work. Can someone tell me what I'm doing wrong?
Option Explicit
Private Sub Worksheet_Change(ByVal Target As Range)
Dim cell As Range, LR As Long, NR1 As Long, NR2 As Long
If Not Intersect(Target, Range("E4")) Is Nothing Then
Application.EnableEvents = False
Range("E21:N30").ClearContents
NR1 = 21
NR2 = 21
With Sheets("Sheet2")
.AutoFilterMode = False
.Rows(1).AutoFilter 3, "*" & Range("E4") & "*"
LR = .Range("C" & .Rows.Count).End(xlUp).Row
If LR > 1 Then
For Each cell In .Range("M2:M" & LR).SpecialCells(xlVisible)
Select Case UCase(cell.Value)
Case "ME"
Range("E" & NR1).Value = .Cells(cell.Row, "K").Value
Range("H" & NR1).Value = .Cells(cell.Row, "B").Value
Range("I" & NR1).Value = .Cells(cell.Row, "I").Value
NR1 = NR1 + 1
Case "THEM"
Range("J" & NR2).Value = .Cells(cell.Row, "K").Value
Range("M" & NR2).Value = .Cells(cell.Row, "B").Value
Range("N" & NR2).Value = .Cells(cell.Row, "I").Value
NR2 = NR2 + 1
End Select
Next cell
Else
Range("E21") = "none"
End If
.AutoFilterMode = False
End With
Application.EnableEvents = True
End If
End Sub
Bookmarks