+ Reply to Thread
Results 1 to 3 of 3

VBA Stop Macro On Error

  1. #1
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    VBA Stop Macro On Error

    Hi guys, I have the code below. It creates and names new sheets based on a list. However, I want to add a messagebox wherein if an error occurs, it would say Message Here then stops and exits the sub.


    Sub Addsheet()
    'Declaring the Variables
    Dim i As Integer
    Dim LastRow As Integer

    'Finding Last Row in Sheet1
    LastRow = Worksheets("Sheet1").Cells(Worksheets("Sheet1").Rows.Count, "A").End(xlUp).Row

    'Using For Loop to Add Sheets by Cell Value
    For i = 1 To LastRow
    Sheets.Add
    ActiveSheet.Name = Worksheets("Sheet1").Cells(i, 1).Value
    Next i


    End Sub

  2. #2
    Forum Expert Arkadi's Avatar
    Join Date
    02-13-2014
    Location
    Smiths Falls, Ontario, Canada
    MS-Off Ver
    Office 365
    Posts
    5,059

    Re: VBA Stop Macro On Error

    Your post does not comply with Rule 2 of our Forum RULES. Use code tags around code.

    Posting code between [CODE]Please [url=https://www.excelforum.com/login.php]Login or Register [/url] to view this content.[/CODE] tags makes your code much easier to read and copy for testing, it also maintains VBA formatting.

    Highlight your code and click the # icon at the top of your post window. More information about these and other tags can be found at http://www.excelforum.com/forum-rule...rum-rules.html

    Please edit your code to fix that issue.

    That said, here is a solution:

    Please Login or Register  to view this content.
    Last edited by Arkadi; 03-21-2019 at 07:48 AM.
    Please help by:

    Marking threads as closed once your issue is resolved. How? The Thread Tools at the top
    Any reputation (*) points appreciated. Not just by me, but by all those helping, so if you found someone's input useful, please take a second to click the * at the bottom left to let them know

    There are 10 kinds of people in this world... those who understand binary, and those who don't.

  3. #3
    Forum Contributor
    Join Date
    01-15-2015
    Location
    philippines
    MS-Off Ver
    Excel 365
    Posts
    116

    Re: VBA Stop Macro On Error

    Thank you. Will do that next time.
    Your solution did the job! Thank you so much.

+ 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] Need Macro to Stop and Show Message When Error, or Continue
    By Phillycheese5 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-23-2018, 01:25 PM
  2. Macro VBA to stop error when no data etc
    By will2k in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 08-15-2016, 01:02 PM
  3. Return Error if 2 Conditions are Met (Stop Macro)
    By kevingcp in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-14-2015, 12:49 PM
  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. Stop a Macro if Criteria not met and Show Error Message
    By m3hool in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-17-2013, 10:12 AM
  6. [SOLVED] Macro to Save file as PDF with Error to stop if name already exists
    By jan mason in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 05-08-2013, 08:54 AM
  7. How Do I stop this macro from running if there is an error?
    By jwichern1 in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 03-03-2011, 03:13 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