+ Reply to Thread
Results 1 to 7 of 7

Inserting a message box when no data is found and exit vba.

  1. #1
    Registered User
    Join Date
    03-15-2024
    Location
    California
    MS-Off Ver
    365
    Posts
    18

    Question Inserting a message box when no data is found and exit vba.

    Hello, I found a print vba code that works in my excel 365 sheet, but if someone hits the print button and there is no data in Column D the sheet locks up and has to be reset from the VBA Project. I've put the vba code below. I just need to know how to modify this code, so if there is no data in column D a message appears stating "No Data Found" then automatically exits the program without having to be reset. Thank you in advance for any assistance.


    Please Login or Register  to view this content.

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: Inserting a message box when no data is found and exit vba.

    Find will raise an error if you try to refer to its row when nothing was found. Easiest thing is to trap the error.
    Please Login or Register  to view this content.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,100

    Re: Inserting a message box when no data is found and exit vba.

    Maybe this:

    Please Login or Register  to view this content.
    Trevor Shuttleworth - Retired Excel/VBA Consultant

    I dream of a better world where chickens can cross the road without having their motives questioned

    'Being unapologetic means never having to say you're sorry' John Cooper Clarke


  4. #4
    Registered User
    Join Date
    03-15-2024
    Location
    California
    MS-Off Ver
    365
    Posts
    18

    Re: Inserting a message box when no data is found and exit vba.

    You're suggestion worked perfect. Thank you.

  5. #5
    Registered User
    Join Date
    03-15-2024
    Location
    California
    MS-Off Ver
    365
    Posts
    18

    Re: Inserting a message box when no data is found and exit vba.

    The suggestion from 6StringJazzer worked and I wanted to thank you for responding to my post. Thanks again.

  6. #6
    Forum Guru TMS's Avatar
    Join Date
    07-15-2010
    Location
    The Great City of Manchester, NW England ;-)
    MS-Off Ver
    MSO 2007,2010,365
    Posts
    48,100

    Re: Inserting a message box when no data is found and exit vba.

    You're welcome.



    Also, you may not be aware that you can thank those who have helped you by clicking the small star icon (Next to Add Reputation) located in the lower left corner of the post in which the help was given. By doing so you can add to the reputation(s) of those who helped.

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,758

    Re: Inserting a message box when no data is found and exit vba.

    Quote Originally Posted by TMS View Post
    Maybe this:
    Probably better than mine because it avoids raising the error in the first place.

+ 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] Display Confirmation Message When Specific Data Not Found
    By swordswinger710 in forum Excel Programming / VBA / Macros
    Replies: 63
    Last Post: 09-06-2016, 11:40 AM
  2. when lookup value does not found then exit sub
    By zico8 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-25-2015, 09:18 AM
  3. Message box if duplicate found and clear the data from corresponding cells
    By sahal in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 08-01-2015, 06:00 AM
  4. Message or Data Member Not Found?
    By kestefon in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-05-2014, 04:56 PM
  5. [SOLVED] Search for value and exit macro if found
    By hutch@edge.net in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 01-08-2014, 09:38 PM
  6. [SOLVED] Code to give message if Filtered value not found in data
    By dinesh_ltjd in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 05-29-2013, 12:12 PM
  7. Data,Filter,AutoFilter, #records found message?
    By boomer in forum Excel General
    Replies: 0
    Last Post: 03-16-2005, 11:46 AM

Tags for this Thread

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