+ Reply to Thread
Results 1 to 12 of 12

Use of many alternatives after elseif

  1. #1
    Registered User
    Join Date
    05-12-2020
    Location
    Lima,Peru
    MS-Off Ver
    2016
    Posts
    25

    Use of many alternatives after elseif

    Hello friends, thanks for your time. Please check the image.
    LINE01 BUTTON.jpg
    I want assign a specific color to the first line (from the first row) then I create this code using macro record.

    Please Login or Register  to view this content.
    But for the yellow color RGB(47, 204, 11) I have different conditions not only "Su<Ma", I want the code can considerate other options like "Su<Mo", "Su<Me", "Su<Ju", etc.
    How I can do that... In excel we have =IF(L5="Su<Ma, L5="Su<Mo", ...) but in macro I don't have an idea how it works.
    Please if you can teach me, it very useful.

    Obviously, if I can work directly in the ActiveSheet and do without using a button it be wonderful.

    Thanks so much.
    Last edited by Vladi108mb; 12-16-2020 at 07:18 AM.

  2. #2
    Valued Forum Contributor
    Join Date
    01-16-2012
    Location
    England
    MS-Off Ver
    MS 365
    Posts
    1,397

    Re: Use of many alternatives after elseif

    Not clear whether you want the line to change colour with each selection? If so, something like this?

    Please Login or Register  to view this content.

    But if you are keeping the line at the same colour whatever the 'date' span, why have it as a Criteria at all (Other than perhaps checking the day cell is not blank)?

    Ochimus
    Last edited by Ochimus; 12-08-2020 at 08:49 PM.

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

    Re: Use of many alternatives after elseif

    Please Login or Register  to view this content.
    Ben Van Johnson

  4. #4
    Registered User
    Join Date
    05-12-2020
    Location
    Lima,Peru
    MS-Off Ver
    2016
    Posts
    25

    Re: Use of many alternatives after elseif

    Excellent!!!! You catch the idea!! So happy for reducing the lines of code!!!

  5. #5
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Use of many alternatives after elseif

    If you want the same colour for multiple values, you can put them on the same Case line:

    Please Login or Register  to view this content.
    or maybe you just need:

    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  6. #6
    Registered User
    Join Date
    05-12-2020
    Location
    Lima,Peru
    MS-Off Ver
    2016
    Posts
    25

    Re: Use of many alternatives after elseif

    Hello Rorya, nice answer... then if I use first recommendation, can I do it in this way?

    Please Login or Register  to view this content.
    But about If left$(Range("L5").Value, 3) = "Su<" then
    I like it so much because is a very more compact code... but how I can use it if I need other cases for the same L5: "Mo<", "Me<", "Ju<" etc.

    Thanks so much for your time!!
    Last edited by Vladi108mb; 12-16-2020 at 07:18 AM.

  7. #7
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Use of many alternatives after elseif

    You could do a similar thing:

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-12-2020
    Location
    Lima,Peru
    MS-Off Ver
    2016
    Posts
    25

    Re: Use of many alternatives after elseif

    Wow! Perfect!! It let me use one unique button to fix colors for many lines at the same time.
    I will use it for many other parts of my project.

    Thank you so much!

  9. #9
    Registered User
    Join Date
    05-12-2020
    Location
    Lima,Peru
    MS-Off Ver
    2016
    Posts
    25

    Re: Use of many alternatives after elseif

    Hello Rorya, I am at this point... but now I need to apply the same conditions to the lines generated from L6, L7, L8, L9, L10, ... , L15
    What is the correct way? I try to change the range to (Range("L5:L15") but don't work


    Please Login or Register  to view this content.
    and try again with (Range("L5:L15") but don't work!

    Please, I need again your expertise. Thanks for your time.
    Last edited by Vladi108mb; 12-16-2020 at 07:17 AM.

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

    Re: Use of many alternatives after elseif

    Vladi108mb, Code tag are required....

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

    Re: Use of many alternatives after elseif

    Please Login or Register  to view this content.

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,280

    Re: Use of many alternatives after elseif

    It may also be that you can reduce the checks to just the first two letters:

    Please Login or Register  to view this content.
    and so on.

+ 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. IF and ElseIf
    By DCRAIG3389 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-08-2016, 12:30 PM
  2. [SOLVED] When ElseIf condition is met, the statements under elseif are not happening.
    By excelkann in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-07-2016, 12:40 PM
  3. If / ElseIf within For Each?
    By pwells in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 06-26-2014, 10:35 AM
  4. Code stepping in to elseif statement when elseif is definitely not true
    By DFrank231 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 02-13-2013, 05:31 PM
  5. If Elseif elseif problem
    By tjbillund in forum Excel General
    Replies: 3
    Last Post: 08-10-2011, 07:02 AM
  6. [SOLVED] if elseif
    By flow23 in forum Excel General
    Replies: 0
    Last Post: 11-14-2005, 10:15 AM
  7. [SOLVED] Re: IF..Then..ELSE.. ELSEIF
    By rjamison in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 06-13-2005, 08: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