I am writing a code to validate my data and what this one is doing is adding back accidently deleted rows. I am using autofilter on the two sheets to compare and run an if statement. I want to be able to copy/return the value of the filtered sheet by using its cell position (ie: Cells(1, 3).SpecialCells(xlCellTypeVisible).Value) but can't figure out the way to do so. Anyone know how? Thanks! My code so far:
Option Explicit
Private Sub UndoAccidentalDelete()
Dim rRange As Range
Dim c As Range
Dim mRange As Range
Dim chkRange As Range
Dim mCount, chkCount, I, J As Long
'Enter range to filter for
Set rRange = Sheets("Sheet31").Range("A2:A176")
'Enter range for data before deletion
Set mRange = Sheets("clean1").Range("A:A")
'Enter range for items meant to be deleted
Set chkRange = Sheets6.Range("J:J")
For Each c In rRange
mRange.AutoFilter Field:=1, Criteria1:=c
mCount = mRange.AutoFilter.Range.Rows.SpecialCells(xlCellTypeVisible).Count
chkRange.AutoFilter Field:=1, Criteria1:=c
chkCount = chkRange.AutoFilter.Range.Rows.SpecialCells(xlCellTypeVisible).Count
For I = 1 To mCount
For J = 1 To chkCount
If mName = chkName Then
GoTo NextI
Else
Sheets("clean1").Cells(mCount, 6)
Next J
NextI:
Next J
End Sub
Bookmarks