+ Reply to Thread
Results 1 to 27 of 27

How to make this worksheet action work with the CASE statement

  1. #1
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    How to make this worksheet action work with the CASE statement

    i have the following routine that works, now i would like to expand it's capabilities to utilize the CASE statement

    Please Login or Register  to view this content.
    here is what i tried and is not working (but the "Approved" string works, just not the other cases)

    Please Login or Register  to view this content.
    thoughts?
    Last edited by dmcgov; 08-01-2017 at 01:32 PM.

  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: How to make this worksheet action work with the CASE statement

    Just use Case "string", not the mathematical operator = which will cause problems:

    Please Login or Register  to view this content.
    The Is = .... would result in a numerical comparison, which for a string is usually 0
    Last edited by Arkadi; 08-01-2017 at 01:34 PM.
    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
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    thanks arkadi, i fixed the code for that but it is still only working for the string "Approved". Doesn't work for anything else. Should i upload the excel file?

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

    Re: How to make this worksheet action work with the CASE statement

    The file would be the easiest way to see what is up, yes.

  5. #5
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    Here it is, thanks for helping out.
    Attached Files Attached Files

  6. #6
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to make this worksheet action work with the CASE statement

    Why are you using Address here? Don't you want the value of Target?
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  7. #7
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    i copied that code from an example. are you telling me that just "Target" by itself will give me the cell information?

    fyi it returns a fixed address, like $P$15. which is the information that i need (so i can grab row 15 in this example)
    Last edited by dmcgov; 08-01-2017 at 02:40 PM.

  8. #8
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: How to make this worksheet action work with the CASE statement

    In your Select Case are you trying to check the address of Target or the value of Target?

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

    Re: How to make this worksheet action work with the CASE statement

    Doh big oversight on my part

  10. #10
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    i need the row number from the cell that has changed, in this case to "Approved". Approved is the contents of the cell, but i need the cell address so i can grab just the row, that way i know what to email to the user.

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

    Re: How to make this worksheet action work with the CASE statement

    Try:

    Please Login or Register  to view this content.
    Target is the cell (or cells) that changed... Notice it COULD be more than one cell if the user pastes values in multiple rows which may cause you headaches.
    Target.Address is the address of the range that changed, .Value will work for a single cell changing.
    Target.Row will return the row number.
    Last edited by Arkadi; 08-01-2017 at 02:49 PM.

  12. #12
    Forum Guru
    Join Date
    03-02-2006
    Location
    Los Angeles, Ca
    MS-Off Ver
    WinXP/MSO2007;Win10/MSO2016
    Posts
    12,626

    Re: How to make this worksheet action work with the CASE statement

    Please Login or Register  to view this content.
    Last edited by protonLeah; 08-01-2017 at 02:58 PM.
    Ben Van Johnson

  13. #13
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    arkadi,

    I figured it out. i had the code in "ThisWorkbook" and not on the Summary sheet. Now everything is working fine. Thanks for your help.

  14. #14
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    oops, didnt figure it out. still not working as expected. i will load up a workbook so that i can show you what is not working.

  15. #15
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    oops, didnt figure it out. still not working as expected. i will load up a workbook so that i can show you what is not working.

  16. #16
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    ok here is what i have (that works as a case statement)

    Please Login or Register  to view this content.
    note that if i make any changes to the code, then it breaks and will not work at all, even if i undo in the debugger.

    here is the code that i want in each case statement:

    Please Login or Register  to view this content.
    how can i use the code above to fit in to my case statements?
    Last edited by dmcgov; 08-02-2017 at 11:10 AM.

  17. #17
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    so i have tried to not use the case statement and just do an if-then-ElseIf but that is not working for me at all. can anyone help out?

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

    Re: How to make this worksheet action work with the CASE statement

    Well i must say... The file you said you were adding but ndver did, helped a lot

  19. #19
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    yup, my bad. sorry arkadi for that. here it is. note that i added sheet 1 and 2 to show the case statement in work. the rest is on the summary sheet (only approved works)

    thanks again for helping out.

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

    Re: How to make this worksheet action work with the CASE statement

    I don't understand... the code you provided says "approved" as part of the message, so how can it apply to other case statements? Are you trying to make the code send the same email for each "Case" option, but specifying whether the items is Approved, on Hold, No, or Written?

    Your Case code is missing and "End With" for the "With Sendrng" block, but otherwise should work fine.

  21. #21
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    Sorry if i am confusing you. The code on the summary sheet only works with "Approved". I want it to work with "Hold", "No", "Written" as well. i would like to use the case statement as opposed to an if-then statement to do this. the sheet 1 and 2 show that i know how to write a case statement, i just cant get the code from summary to work this way. can this be done?

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

    Re: How to make this worksheet action work with the CASE statement

    Well... If I understand correctly then this may do the trick.... I noticed Status can only be "Approved" in the validation at the moment, but I did test with "Hold" and the case statement works.

    I left in your If statement but commented it out, changes or new lines in red below:

    Please Login or Register  to view this content.

  23. #23
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    thanks arkadi, one quick question. should the "StopMacro" be placed just before the "End Select"? i know that i can't just have multiple copies of the same label.

    thoughts?

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

    Re: How to make this worksheet action work with the CASE statement

    Oops... I didnt think that part through... My apologies.
    As the code is now, it wouldnt matter since the messagebox wont cause an error im sure. But yes you are 100% correct. Cut the label and the code that goes with it, and place it just before End Select
    Last edited by Arkadi; 08-03-2017 at 08:40 AM. Reason: Correction in red

  25. #25
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    thanks arkadi, that did the trick. now everything is working as it should. the great news about doing it this way is that i can use this change macro on many different types of worksheets. I do appreciate all of your help.

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

    Re: How to make this worksheet action work with the CASE statement

    Glad I could help Sorry it took me a bit to catch on to the requirements

  27. #27
    Valued Forum Contributor dmcgov's Avatar
    Join Date
    11-11-2015
    Location
    Florida, USA
    MS-Off Ver
    Office 365 Business
    Posts
    1,518

    Re: How to make this worksheet action work with the CASE statement

    you helped out for sure. no worries. thanks again

+ 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. Trying to make this if statement work
    By Orginlock in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-16-2016, 03:58 AM
  2. [SOLVED] i have an if then statement that works, how to make it work as a with or case statement
    By dmcgov in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 06-03-2016, 03:34 PM
  3. How to make this SumIf statement work
    By Rheanna in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 10-29-2014, 01:22 PM
  4. [SOLVED] IF statement I cant make work
    By DrGnBld in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 06-19-2014, 01:18 AM
  5. Anyone actually get Case statement to work ... ?
    By ForestFeeder in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-21-2006, 11:15 AM
  6. Anyone actually get Case statement to work ... ?
    By ForestFeeder in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-21-2006, 10:50 AM
  7. Select case statement - it will not work and i dont understand why! :o(
    By Thomas in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 09-26-2005, 01:05 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