+ Reply to Thread
Results 1 to 2 of 2

Excel VBA - How to add command to stop executing the macro

  1. #1
    Registered User
    Join Date
    06-27-2020
    Location
    India
    MS-Off Ver
    365
    Posts
    24

    Excel VBA - How to add command to stop executing the macro

    Dear All,
    With the help of ExcelForum members, I have created following Macro, which
    is successfully getting executed and bringing the desired results. However,
    the problem is, even there is no data to transfer, the Macro is getting executed.
    I want to add a command line, if there is not data, then MsgBox should appear
    with message "NOTHING TO TRANSFER".

    Please help with suitable command line.

    ---------------------
    Sub TransferData()

    Application.ScreenUpdating = False
    Application.DisplayAlerts = False

    Range("Y1", Range("Y" & Rows.Count).End(xlUp)).AutoFilter 1, "Complete"
    Range("A5", Range("AC" & Rows.Count).End(xlUp)).Copy Sheet2.Range("A" & Rows.Count).End(xlUp)(2)
    Range("A5", Range("AC" & Rows.Count).End(xlUp)).Delete
    [Y1].AutoFilter

    Application.CutCopyMode = False
    Application.DisplayAlerts = True
    Application.ScreenUpdating = True
    Sheet2.Select

    End Sub
    -----------------------

  2. #2
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    22,064

    Re: Excel VBA - How to add command to stop executing the macro

    Please use code tags when posting code.

    Try this:

    Please Login or Register  to view this content.
    Everyone who confuses correlation and causation ends up dead.

+ 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] Stop macro from executing multiple times with multiple clicks
    By marvrulz in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 05-20-2020, 01:47 PM
  2. How to set a stop command in the macro
    By JayDeJay in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-06-2015, 02:57 AM
  3. Why is Excel VBA executing a command corretly in debug modus but not in normal mode?
    By flextexmex in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-02-2015, 06:49 AM
  4. How to re run macro after ERROR' Command will stop the debugger'
    By chevenowner in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-10-2014, 07:12 AM
  5. macro check for values before executing command
    By Jakes in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-02-2012, 12:59 PM
  6. Excel 2007 crashes when executing activeworkbook.close command
    By rpradeepjain in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 11-10-2010, 07:28 AM
  7. Executing the delete command in a macro
    By punter in forum Excel General
    Replies: 1
    Last Post: 11-16-2006, 03: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