+ Reply to Thread
Results 1 to 14 of 14

i have an if then statement that works, how to make it work as a with or 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

    i have an if then statement that works, how to make it work as a with or case statement

    i have this bit of code that works.

    Please Login or Register  to view this content.
    what i want is it to work with the code below, so i tried a multiple IF statement that failed, basically i put an "if xyz... then if sheets..." but the compiler balked at that. so now that i know it wont work that way, can i wrap the code using a WITH statement or a CASE statement to make it work? just a note that i have several of these IF xyz statements so the solution needs to work with that.

    Please Login or Register  to view this content.
    this failed below

    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
    MS365 Family 64-bit
    Posts
    24,721

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    Try it this way

    Please Login or Register  to view this content.
    You have to be careful with And but in this case I think it's what you want.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    Try this:

    Please Login or Register  to view this content.

  4. #4
    Forum Contributor
    Join Date
    10-13-2012
    Location
    Southern California
    MS-Off Ver
    Excel 2007
    Posts
    401

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    I posted before I saw 6StringJazzer's response.

    His answer is good too. Both his code and mine will do the exact same thing.

  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: i have an if then statement that works, how to make it work as a with or case statemen

    many thanks to both of you, gold stars all around!

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    Oh, and you should really do it this way when your If conditions are mutually exclusive:

    Please Login or Register  to view this content.

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

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    And I should also add that GoTo bothers me. I don't want to pry, but I would be willing to review your entire application if you want it more thoroughly vetted. Can you show all your code?

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

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    i cant post it here, its too big.

    i tried to upload it through attachments but the interface changed and i don't know how to attach it. if you can help me with that, i will post the code.

    thanks 6stringjazzer

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

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    any thoughts on how to do this?

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    To attach a file, click Go Advanced under the edit window, then on the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and then Upload a file. Then close the window and the file will be shown as an attachment in your post.

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

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    i did everything that you mentioned, this part fails "Then close the window and the file will be shown as an attachment in your post."

    i do the upload, and then close the window. nothing appears in the post...

    any thoughts?

    advanced screen snapshot.jpg


    hmm now it appears once i pick an image to upload. not sure why...
    Attached Files Attached Files
    Last edited by dmcgov; 05-31-2016 at 10:24 AM.

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: i have an if then statement that works, how to make it work as a with or case statemen

    I have a few high-level suggestions but can't offer any rewritten code without having your file to see how everything works. Here are my thoughts.

    You should use Option Explicit and declare all your variables.

    You start out with 12 If statements. Each one asks for user input, and the first time they say Yes then you GoTo another line. I would do this with a UserForm that has 12 option buttons and an OK button instead. That would be so much faster than making the user say No 11 times and finally say Yes.

    Not sure why you are making calls like this
    Please Login or Register  to view this content.
    You can just do this
    Please Login or Register  to view this content.
    You generally do not need to Select objects to work on them, unless you need the user to see what is selected. This is typical of what the macro recorder does.
    Please Login or Register  to view this content.
    can be done like this
    Please Login or Register  to view this content.
    You then have two long Case Select statements on xyz. They can be combined into one.
    Please Login or Register  to view this content.
    can be condensed to this (the first case is weird because you have the OCV case commented out)
    Please Login or Register  to view this content.
    That's all I have for now.

  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: i have an if then statement that works, how to make it work as a with or case statemen

    thanks so much 6stringjazzer, i will make changes to my code to reflect what you have done. gold stars all around!

  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: i have an if then statement that works, how to make it work as a with or case statemen

    testing testing testing
    Attached Images Attached Images
    Attached Files Attached Files
    Last edited by dmcgov; 06-03-2016 at 03:37 PM.

+ 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] If Statement - works with first if but the other 11 won't work.
    By C0sm0s in forum Excel General
    Replies: 6
    Last Post: 05-18-2016, 11:03 AM
  2. [SOLVED] IF statement I cant make work
    By DrGnBld in forum Excel Formulas & Functions
    Replies: 17
    Last Post: 06-19-2014, 01:18 AM
  3. [SOLVED] Utilize a Select Case Statement in Target Intersect Statement
    By max57 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 07-29-2009, 08:55 PM
  4. Anyone actually get Case statement to work ... ?
    By ForestFeeder in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-21-2006, 11:15 AM
  5. [SOLVED] 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
  6. 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
  7. [SOLVED] How can i make this work within an IF statement: (41<=Cell<=46)
    By velopoav in forum Excel - New Users/Basics
    Replies: 3
    Last Post: 04-10-2005, 10:06 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