+ Reply to Thread
Results 1 to 3 of 3

[SOLVED] Pass to Next Step in Macro if no cells are visible after filter

  1. #1
    Registered User
    Join Date
    10-11-2019
    Location
    Prague, Czech Republic
    MS-Off Ver
    Office 365
    Posts
    16

    [SOLVED] Pass to Next Step in Macro if no cells are visible after filter

    Hello everyone.

    New guy here.

    I just started with this whole VBA thing and i've encountered a problem I cannot overcome by myself (yet, hopefully).


    On my macro I have an autofilter that might give zero reults, meaning that when applied, there will be no cells visible.

    If it happens i need to have the macro skip a couple of steps and continues to run in case the above situation occours.


    This is the code:


    Range("A1").Activate

    Selection.AutoFilter Field:=6, Criteria1:=Array( _
    "AB US"), Operator:=xlFilterValues

    Selection.AutoFilter Field:=2, Criteria1:=Array( _
    "<>-")


    LastRow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row


    Range("A2:F" & LastRow).SpecialCells(xlCellTypeVisible).Copy

    ActiveSheet.Paste Destination:=Workbooks(ActionLog).Sheets("Action Log").Range("D" & lastrow2 + 1)

    Workbooks(ActionLog).Activate

    LastRow3 = ActiveSheet.Cells(Rows.Count, "D").End(xlUp).Row

    Dim u As Integer

    For u = lastrow2 + 1 To LastRow3

    Range("C" & u).Value = "US Import"

    Next u

    lastrow4 = ActiveSheet.Cells(Rows.Count, "B").End(xlUp).Row

    Range("B" & lastrow4).Select

    Selection.AutoFill Destination:=Range("B" & lastrow4 & ":B" & LastRow3)

    The bold line is where the macro crashes at the moment and I need it to continue and skip the steps after the bold line in case no cells are visible.

    How can i do it?


    Thanks in advance for the help!
    Last edited by mgnab; 10-23-2019 at 05:42 AM.

  2. #2
    Forum Expert PaulM100's Avatar
    Join Date
    10-09-2017
    Location
    UK
    MS-Off Ver
    Office 365
    Posts
    2,108

    Re: Pass to Next Step in Macro if no cells are visible after filter

    Add an on error step: https://docs.microsoft.com/en-us/dot...rror-statement
    Click the * to say thanks.

  3. #3
    Registered User
    Join Date
    10-11-2019
    Location
    Prague, Czech Republic
    MS-Off Ver
    Office 365
    Posts
    16

    Re: Pass to Next Step in Macro if no cells are visible after filter

    Perfect!

    Thanks for the suggestion!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Paste Visible Cells Only - works only if step through code manually
    By dflak in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-10-2019, 10:36 AM
  2. [SOLVED] Sum visible cells two by two when automatic filter is applied
    By Lalla in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 10-18-2014, 07:45 AM
  3. Vlookup on Visible cells after filter particular value
    By [email protected] in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-07-2014, 10:29 AM
  4. [SOLVED] Copy Filter Data and paste it on another workbook with special cells(Only Visible Cells)
    By HaroonSid in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-13-2014, 07:59 AM
  5. Pass cells from Custom Filter to a Text Box (w concatenation) using VBA Code
    By Cirenav in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-11-2013, 04:46 PM
  6. Copy to Visible cells after filter
    By vandanavai in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-23-2009, 01:29 PM
  7. Sum according to Auto filter non visible cells
    By ElmerS in forum Excel General
    Replies: 9
    Last Post: 08-10-2009, 12:45 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1