hi,
I am having a serious trouble in my MACRO, i have tried to watch some youtube videos but nothing works.
The Idea is, I want the MACRO to go to a specific column and filter it, lets say with the criteria 2934, and then, take whatever range is shown (it is not always the same, and sometime may not appear) and paste it to another sheet.
Everything seems great, however, if no do data are available for the criteria 2934, it will copy the whole range/table without any filter! and this will cause a huge mess in my data.
I have tried to use the following code, but it is not working + sometime give me the opposite result (for example, if there is a data for the criteria, it will show the message box!).
here is my code:
Dim autofilter As Range
Dim rng As Range
Sheets("Items").Select
ActiveSheet.Range("d2").autofilter Field:=4, Criteria1:="2934"
If autofilter Is Nothing Then
MsgBox "No data available"
Sheets("Items").Select
ActiveSheet.ShowAllData
Exit Sub
Else
Then I have continued my code to copy the range ..etc.
I am having a serious trouble in my MACRO, i have tried to watch some youtube videos but nothing works.
The Idea is, I want the MACRO to go to a specific column and filter it, lets say with the criteria 2934, and then, take whatever range is shown (it is not always the same, and sometime may not appear) and paste it to another sheet.
Everything seems great, however, if no do data are available for the criteria 2934, it will copy the whole range/table without any filter! and this will cause a huge mess in my data.
I have tried to use the following code, but it is not working + sometime give me the opposite result (for example, if there is a data for the criteria, it will show the message box!).
here is my code:
Dim autofilter As Range
Dim rng As Range
Sheets("Items").Select
ActiveSheet.Range("d2").autofilter Field:=4, Criteria1:="2934"
If autofilter Is Nothing Then
MsgBox "No data available"
Sheets("Items").Select
ActiveSheet.ShowAllData
Exit Sub
Else
Then I have continued my code to copy the range ..etc.