+ Reply to Thread
Results 1 to 11 of 11

Macro to say message if certain criteria are met

  1. #1
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Macro to say message if certain criteria are met

    Hello
    I was hoping somebody could help, i have received lots of help already with my macros for which i am very grateful and have learnt a small bit, unfortunately not enough!. i have had a good go at doing this one myself but find myself at a loss.

    What my macro is trying to achieve is to save a range of data if certain criteria are met.

    The sheet in which the data is held is "sheet3".

    If column S contains the words "resolve wsa" or "resolve list"

    and column U contains the word "open" or column V contains todays date ( not actually 27/10/10 but the data when this is accessed),

    then i wish my macro to then pop up a message box saying, "save your worksheet"
    but if this criteria is not met then i want it to pop a message " saying no need to save"


    Im sure this is quite possible, but im just getting no where with it so any help would be really appreciated.


    Kind regards

    Joe
    Last edited by sandbach; 10-30-2010 at 05:06 PM.

  2. #2
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to say message if certain criteria are met

    Do you want those words to be present anywhere in the column, or just in a certain row?
    What do you want to trigger your macro?
    Is your code running too slowly?
    Does your workbook or database have a bunch of duplicate pieces of data?
    Have a look at this article to learn the best ways to set up your projects.
    It will save both time and effort in the long run!


    Dave

  3. #3
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    Sorry, knew i hadnt been clear enough!

    I intend to add the code on to a button with code on it already.


    sorry to be clearer on the code if in the same row, any row, of a range of preselected data, i want the macro to read it and if in column s contains the words "resolve wsa" or "resolve list"

    and then to read column U and if that contains the word "open" or if column V contains the date on which the data is accessed

    then if these criteria are met, i want it to pop if with a message "you need to save your worklist" but if these criteria are not met, then i want a message to pop up saying" you do not need to save a worklist"


    I have had a good goo at this myself but getting no where and it contains sensitive data so i cannot send the workbook,. but any help really would be appreciated

  4. #4
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to say message if certain criteria are met

    The only thing you've still left out is which rows you want to search. For the purpose of my code below, I've assumed rows 3 - 5. However, to change this just change where lngTop and lnbBottom are defined.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    Thanks very much Dave,

    ill plug that into my workbbok when i get to it tomorrow, hopefully it will do the trick, thanks very much.

  6. #6
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    Hello Dave,

    Right i have tried the code but it doesnt seem to be working i have amended the code but may have messed it up.

    the code i have put in after the first one didnt work, which i think may have been to my lack of info!
    anyway what i have added is

    HTML Code: 
    and it is to correspond with a mock up of the type of data on the attached file, with which rows 7 and 15 meet the criteria to flash up the message "save it" all other rows should flash up the other message as they do not meet the criteria.

    I hope this provides enough information.

    Thanks for ur efforts already.


    Joe
    Attached Files Attached Files

  7. #7
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to say message if certain criteria are met

    I'm very sorry, I miss-read an "or" with the date and open/closed in your initial request.

    I ran your code in your example and it worked for me. I'm not sure what text editor you are using, but my vba didn't interpret your quote marks correctly. After fixing them and changing the reference to sheet 1 (instead of sheet 4) it told me to save after row 7 and row 15.

  8. #8
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    Ha, i knew i hadnt written it the most understandable way!

    When the data, is returned in that form, when it scans the whole document, it was working correctly with the first IF

    but through trial and error the second IF didnt seem to be working, so it was returning the wrong end instructions.

    i may not have explained this properly, but i need it to check the whole sheet and if any of the rows meet the criteria to then show the save it message

    can u advise if there are any errors in it?

  9. #9
    Forum Expert davegugg's Avatar
    Join Date
    12-18-2008
    Location
    WI, US
    MS-Off Ver
    2010
    Posts
    1,884

    Re: Macro to say message if certain criteria are met

    I'm not sure what else to tell you. I've modified the macro to run in your example, check the workbook I've uploaded. Hopefully that will help.
    Attached Files Attached Files

  10. #10
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    Thanks Dave very much for your efforts.

    I have tested the uploaded workbook with the code in, it seems to be working perfectly except if i have the criteria (a) resolve isa (d) closed and (f) 29.10.10 - yesterdays date

    it returns u should save ur worklist, but this is incorrect, if the date was 30.10.10 - todays date, it should return "u should save ur worklist" but not if its yesterdays?

    Can u advise in anyway?


    Kind regards

    Joe

  11. #11
    Registered User
    Join Date
    09-23-2009
    Location
    liverpool, england
    MS-Off Ver
    Excel 2003
    Posts
    78

    Re: Macro to say message if certain criteria are met

    ha the date was in wrong format!!!!!


    works perfectly now, thank u very much!!

+ 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