• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Getting Error if the there is no data for the filtered values

Sunil113

New Member
Hi Team,

I am getting an error if there is no data for the filtered values. Please look in to the code and help me to resolve the error. If there is no data it needs to continue with next steps.
Please find the code below

>>> use code - tags <<<
Code:
Sub Copy_Filtered_data_Raw()
Dim Count_Col, Count_Row As Integer
Dim Raw, Modified As Worksheet
Dim lDestLastRow2 As Long

Worksheets("Modified").Activate

Set Modified = ThisWorkbook.Sheets("Modified")
Set Raw = ThisWorkbook.Sheets("Raw")


Count_Col = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlToRight)))
Count_Row = WorksheetFunction.CountA(Range("A1", Range("A1").End(xlDown)))

ActiveSheet.Range("A1").AutoFilter Field:=3, Criteria1:=68

Modified.Range(Cells(2, 2), Cells(Count_Row, Count_Col)).SpecialCells(xlCellTypeVisible).Copy

lDestLastRow2 = Raw.Cells(Raw.Rows.Count, "B").End(xlUp).Offset(1).Row

Raw.Range("B" & lDestLastRow2).PasteSpecial xlPasteValues

Application.CutCopyMode = False

Worksheets("Modified").ShowAllData
Worksheets("Modified").AutoFilterMode = False

Worksheets("Raw").Columns.AutoFit


End Sub
 

Attachments

  • Excel error.PNG
    Excel error.PNG
    3.6 KB · Views: 2
  • Excel error 1.PNG
    Excel error 1.PNG
    30.3 KB · Views: 2
Last edited:
Sunil113
I'm wondering ...
You seems to filter from Master Tracker -sheet, which is active and
You're copying from Modified -sheet with max values (Count_Col and Count_Row) from Master Tracker -sheet.
Have You verified/checked - what are Count_Col and Count_Row -values?
There are possibilities to check number of filtered row,
but before that - what should happen with Your code?
 
Sunil113
I'm wondering ...
You seems to filter from Master Tracker -sheet, which is active and
You're copying from Modified -sheet with max values (Count_Col and Count_Row) from Master Tracker -sheet.
Have You verified/checked - what are Count_Col and Count_Row -values?
There are possibilities to check number of filtered row,
but before that - what should happen with Your code?
Sorry,
Modified worksheet needs to be active sheet, updated post with modified code.

I have data in my modified worksheet and needs to get filtered with a certain value and copy the filtered data to raw worksheet.

If the value mentioned in the code (68) is available, the code is copying the related info to raw sheet. However if I don't have the value it is throwing an error. Instead of throwing an error it needs to continue to next step inthe code.


If there isn't any data with 68 in col 3 then count_row/col is showing as 1.
If data is available then it was showing the count along with the header.

Thanks for your help.
 
Last edited:
Sunil113
I would do that ... other way.
You should able to attach a sample Excel-file, which shows Your challenge.
or
You could continue with Your used syntax
with count_row/col is showing as 1 information to skip Your copy & paste.
 
Back
Top