Hi Mr Excel,
I am having some trouble putting together the code to cut the visible rows from a filtered list on one sheet, to paste to another worksheet.
These are the steps I am trying to achieve:
1. Filter a range (named “List”) based on criteria set in variable vCriteria
2. Set the visible rows (excl. header row) to a variable named DList
3. Cut (remove) from database tab data set in DList, not leaving any blank rows after the list is unfiltered
4. Go to the archive tab, find the last row in the archive list and paste data contained in DList
Below is the code I have so far. The first step is no problem. The second step, I think works, but the third and the fourth steps, I am really having troubles with. Any help would be much appreciated!
Best regards,
Shirley
Sub Filtertest()
Dim vCriteria As Range
Dim rTable As Range
Dim DList As Range
Set vCriteria = Range("criterion")
Set rTable = Range("List")
'Filter database based on criteria in cell named "criterion"
rTable.AutoFilter field:=2, Criteria1:=vcriteria
‘set visible cells to variable named DList (excluding headers)
With Sheets("Database").AutoFilter.Range
On Error Resume Next
Set DList = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If DList Is Nothing Then
MsgBox "No data to copy"
'cut visible cells in variable DList from “Database” sheet and paste on sheet named “Archive”
End if
Sheets(“Database”).select
End Sub
I am having some trouble putting together the code to cut the visible rows from a filtered list on one sheet, to paste to another worksheet.
These are the steps I am trying to achieve:
1. Filter a range (named “List”) based on criteria set in variable vCriteria
2. Set the visible rows (excl. header row) to a variable named DList
3. Cut (remove) from database tab data set in DList, not leaving any blank rows after the list is unfiltered
4. Go to the archive tab, find the last row in the archive list and paste data contained in DList
Below is the code I have so far. The first step is no problem. The second step, I think works, but the third and the fourth steps, I am really having troubles with. Any help would be much appreciated!
Best regards,
Shirley
Sub Filtertest()
Dim vCriteria As Range
Dim rTable As Range
Dim DList As Range
Set vCriteria = Range("criterion")
Set rTable = Range("List")
'Filter database based on criteria in cell named "criterion"
rTable.AutoFilter field:=2, Criteria1:=vcriteria
‘set visible cells to variable named DList (excluding headers)
With Sheets("Database").AutoFilter.Range
On Error Resume Next
Set DList = .Offset(1, 0).SpecialCells(xlCellTypeVisible)
On Error GoTo 0
End With
If DList Is Nothing Then
MsgBox "No data to copy"
'cut visible cells in variable DList from “Database” sheet and paste on sheet named “Archive”
End if
Sheets(“Database”).select
End Sub