Worksheet_Change VLookup issue when deleting rows (#N/A in every column)
Hi guys,
I am using Worksheet_Change & VLookup to collect data from a sheet called 'groslijst' into a sheet called 'Wijzigingen'. I am using the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.ScreenUpdating = False
Application.EnableEvents = False
selectedNa = Target.Value
If Target.Column = 1 Then
selectedNum = Application.VLookup(selectedNa, Worksheets("Groslijst").Range("C4:N4000"), 12, False)
If Not IsError(selectedNum) Then
Target.Value = selectedNum
End If
End If
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
This code works fine until I try to delete rows in the 'Wijzigen' sheet with the following code:
Sub RowKiller()
Dim LRow As Long
Dim delRange As Range
With ThisWorkbook.Sheets("Wijzigingen")
.AutoFilterMode = False
LRow = .Range("A" & .Rows.Count).End(xlUp).row
With .Range("A1:A" & LRow)
.AutoFilter Field:=1, Criteria1:="<>"
Set delRange = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
.AutoFilterMode = False
End With
If Not delRange Is Nothing Then delRange.Delete
End Sub
It returns a #N/A that I can't delete. I basically want to run a macro that copies the contents of wijzigingen to another sheet and then deletes all the processed data, leaving empty rows for furture data entry.
I am quite new to VBA so I may have done something very foolish, but any help would be appreciated.
|