Consulting

Results 1 to 20 of 72

Thread: IF statment nested within VBA Code

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #35
    VBAX Regular
    Joined
    Sep 2023
    Posts
    77
    Location
    Hi Paul,

    This looks great but I'm struggling to see where the change is for rC5 cell?

    If the users selects 'Ocean_EU_to_US' in rC3 and any of the below in rC4, then rC5 is visible for them to select either 'Factory Load' or 'CFS Loading'

    Genoa to New York
    Genoa/La Spezia to Los Angeles
    Gdynia to New York
    Gdynia to Los Angeles
    Hamburg to New York
    Hamburg to Los Angeles

    Below example of one of the lanes where different rows are hidden/unhidden depending on what the user selects in rC4 (see previous post #65) (I didn't show all, the rest are in the attachment on post #65)

    Case "Ocean_EU_to_US" & "#" & "Gdynia to New York" & "#" & "Factory Load"    Range("C8:C10").Value = ""
        Range("C11:C17").Value = ""
        Range("C19:C21").Value = ""
        Range("D23:D25").Value = ""
        Range("A5").EntireRow.Hidden = False
        Range("A6").EntireRow.Hidden = True
        Range("A7:A8").EntireRow.Hidden = False
        Range("A9:A18").EntireRow.Hidden = True
        Range("A19").EntireRow.Hidden = False
        Range("A20:A21").EntireRow.Hidden = True
        Range("A22:A25").EntireRow.Hidden = False
        Range("A33:A76").EntireRow.Hidden = True
            
    Case "Ocean_EU_to_US" & "#" & "Gdynia to New York" & "#" & "CFS Loading"
        Range("C8:C10").Value = ""
        Range("C11:C17").Value = ""
        Range("C19:C21").Value = ""
        Range("D23:D25").Value = ""
        Range("A5").EntireRow.Hidden = False
        Range("A6").EntireRow.Hidden = True
        Range("A7:A8").EntireRow.Hidden = False
        Range("A9:A19").EntireRow.Hidden = True
        Range("A20").EntireRow.Hidden = False
        Range("A21").EntireRow.Hidden = True
        Range("A22:A25").EntireRow.Hidden = False
    
        Range("A33:A76").EntireRow.Hidden = True

    The below code is perfect for Air, Overland & Ocean_Asia_to_EU

    Case "Air"      '   -------------------------------------------------------------------------------------------- Mode = Air            rLoading.Value = "Factory Load"
                rLoading.EntireRow.Hidden = True


    However for Ocean_EU_to_US we will have a mixture of

    rLoading.Value = "Factory Load"
    rLoading.Value = "CFS Loading"
    for the lanes :

    Genoa to New York
    Genoa/La Spezia to Los Angeles
    Gdynia to New York
    Gdynia to Los Angeles
    Hamburg to New York
    Hamburg to Los Angeles


    Do have to change the code like the below:

    rLoading.Value = "Factory Load"
    rLoading.EntireRow.Hidden = True
    
    Case "Ocean_EU_to_US"     '   ------------------------------------------------------------ Mode = Ocean EU to US
    rLoading.Value = "Factory Load"
    rLoading.EntireRow.Hidden = True            
    Select Case rLane.Value
                                                 
                    Case "Gdynia To New York"
                        Range("C8@C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A5").EntireRow.Hidden = False
                        Range("A6").EntireRow.Hidden = True
                        Range("A7:A8").EntireRow.Hidden = False
                        Range("A9:A18").EntireRow.Hidden = True
                        Range("A19").EntireRow.Hidden = False
                        Range("A20:A21").EntireRow.Hidden = True
                        Range("A22:A25").EntireRow.Hidden = False
                        Range("A33:A76").EntireRow.Hidden = True
                        ActiveSheet.CheckBoxes("FBC").Value = xlOff
    
    rLoading.Value = "CFS Loading"
    rLoading.EntireRow.Hidden = True            
    Select Case rLane.Value
    Case "Gdynia To New York"
                        Range("C8@C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A5").EntireRow.Hidden = False
                        Range("A6").EntireRow.Hidden = True
                        Range("A7:A8").EntireRow.Hidden = False
                        Range("A9:A19").EntireRow.Hidden = True
                        Range("A20").EntireRow.Hidden = False
                        Range("A21").EntireRow.Hidden = True
                        Range("A22:A25").EntireRow.Hidden = False
                        Range("A33:A76").EntireRow.Hidden = True
                        ActiveSheet.CheckBoxes("FBC").Value = xlOff
    Oo do I bunch all '"CFS Loading"' lanes (rLane) under ones the heading "CFS Loading" and then repeat for all "Factory Loads" lanes?


    I will review again in case it's me and my lack of understanding, highly possible lol

    Once again, your help is highly appreciated sir.
    Last edited by Scuba; 09-25-2023 at 06:02 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •