+ Reply to Thread
Results 1 to 10 of 10

Macro for genearating warning message if a particular cell value is empty

  1. #1
    Registered User
    Join Date
    09-20-2011
    Location
    Swiss
    MS-Off Ver
    Excel 2003
    Posts
    22

    Macro for genearating warning message if a particular cell value is empty

    Hi,

    I am trying to write a macro, which will check the value of D1 value in sheet1 worksheet(i have multiple sheets, and I will call this macro in all the sheets for getting the value from sheet1), if the value is NULL I am displaying a error message, if the feild has a value I am calling the main batch script.But when I am executing the below macro I am getting subscript out of range error. Please let me know what is wrong in the script.


    Please Login or Register  to view this content.
    Thanks,
    Nithya

  2. #2
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro for genearating warning message if a particular cell value is empty

    I'm not sure exactly what you mean by null - Your code indicates that you mean there is no value in the cell, so you could use the following if this is what you want;

    *fixed proper row, column reference

    Please Login or Register  to view this content.
    Please note you also do not indicate where your code haults (I'm assuming not during your other sub, BAISB?).
    Last edited by Medpack; 06-07-2012 at 12:50 AM.

  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
    44,440

    Re: Macro for genearating warning message if a particular cell value is empty

    @Medpack: cells(4, 1) ... ?
    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
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro for genearating warning message if a particular cell value is empty

    Whoops, backwards, 1,4 - thanks for checking =)

  5. #5
    Registered User
    Join Date
    09-20-2011
    Location
    Swiss
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Macro for genearating warning message if a particular cell value is empty

    HI ,

    Thanks for the help.

    I am able to generate a warning message with the below code.But when I entered space and executed it is not generating any warning messages, it is directly calling my sub program. I tried with the trim of the cell.value but still the macro is not generating any warning.Is it possible to generate warning for spaces, or to keep some additional check like, if the first character in the D1 should be always a alphabet B.. some thing from preventing the subprogram to fire if D1 is null or if it contains spaces.

    Please Login or Register  to view this content.
    Thanks,
    Nithya

  6. #6
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro for genearating warning message if a particular cell value is empty

    Yes, you can check the first part and see if it's = to a space by either referring to " " or to chr$(32), which is the character code for space.

    Please Login or Register  to view this content.
    **Edited thanks to the kind macro guru's advice
    If you want to check for alphabetical characters (both upper and lower case) you could use the following;

    Please Login or Register  to view this content.
    Last edited by Medpack; 06-07-2012 at 05:06 PM.

  7. #7
    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
    44,440

    Re: Macro for genearating warning message if a particular cell value is empty

    @Medpack: rather than loop through the alphabet (times 2), can't you just check >= 65 and <= 90?

  8. #8
    Forum Contributor
    Join Date
    05-25-2012
    Location
    California
    MS-Off Ver
    Excel 2010
    Posts
    194

    Re: Macro for genearating warning message if a particular cell value is empty

    Wow, that's pretty cool - didn't realize you could refer to a character in a string and it would return a numerical value that can be compared against another. Thanks!

  9. #9
    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
    44,440

    Re: Macro for genearating warning message if a particular cell value is empty

    @Medpack: you're welcome. Thanks for the rep.

  10. #10
    Registered User
    Join Date
    09-20-2011
    Location
    Swiss
    MS-Off Ver
    Excel 2003
    Posts
    22

    Re: Macro for genearating warning message if a particular cell value is empty

    Thanks Medpack.

    Regards,
    Nithya

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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