Results 1 to 20 of 72

Thread: IF statment nested within VBA Code

Threaded View

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

    OK so when I select 'Gdynia to New York' then nothing changes when is select either 'CFS Loading' or 'Factory Loading' in rLoading

    Maybe I'm not explaining myself clearly here, which if so, I apologise for and thank you for your patience with me.

    I going to try and spell it out for you here.

    rloading is defaulted to 'Factory Loading' for all lanes to begin with and the cell is hidden for all rLanes except those shown below

    rLoading row/cell is only visible for the below mention rMode lanes as its only needs to be changed for those lanes,


    if rLane = 'Gdynia to New York' & 'rLoading' = 'Factory Loading' then row 19 is visible & row 20 is hidden.
    if rLane = 'Gdynia to New York' & 'rLoading' = 'CFS Loading' then row 19 is hidden & row 20 is visible

    This logic is needed for the below lanes as well:


    rLane = Gdynia to New York
    rLane = Gdynia to Los Angeles
    rLane = Hamburg to New York
    rLane = Hamburg to Los Angeles

    The user can select between 'CFS Loading' or 'Factory Loading' when the above lanes are selected, everything else can remain as is.

    I don't need to change anything else as it all works correct, I just need to get the correct line 19 & 20 to hide/unhide based on rLoading selection for the above lanes only.

    Hopefully the above is much clearer direction/vision of what I am trying to attain here

    UPDATE!

    I fixed the code to the below and all appears to be working correctly now

    I can't thank you enough Paul for your help, I've learnt so much in a short space of time, nothing like learning on the job lol

    Once again, big thank you, your a star *

           Case "Gdynia to New York"                    If rLoading.Value = "CFS Loading" Then          '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            Range("C19").EntireRow.Hidden = True
                            Range("C20").EntireRow.Hidden = False
                            Else
                            Range("C19").EntireRow.Hidden = False
                            Range("C20").EntireRow.Hidden = True
                        Range("C8:C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A6").EntireRow.Hidden = True
                        Range("A12:A18").EntireRow.Hidden = True
                        Range("A21").EntireRow.Hidden = True
                        Range("A33:A76").EntireRow.Hidden = True
                        If Range("M29") = False Then Rows("33:76").EntireRow.Hidden = True
                        End If
                                                                               
                     Case "Gdynia to Los Angeles"
                        If rLoading.Value = "CFS Loading" Then          '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            Range("C19").EntireRow.Hidden = True
                            Range("C20").EntireRow.Hidden = False
                            Else
                            Range("C19").EntireRow.Hidden = False
                            Range("C20").EntireRow.Hidden = True
                        Range("C8:C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A6").EntireRow.Hidden = True
                        Range("A12:A18").EntireRow.Hidden = True
                        Range("A20:A21").EntireRow.Hidden = True
                        Range("A33:A76").EntireRow.Hidden = True
                        If Range("M29") = False Then Rows("33:76").EntireRow.Hidden = True
                        End If
                        
                    Case "Hamburg to New York"
                        If rLoading.Value = "CFS Loading" Then          '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            Range("C19").EntireRow.Hidden = True
                            Range("C20").EntireRow.Hidden = False
                            Else
                            Range("C19").EntireRow.Hidden = False
                            Range("C20").EntireRow.Hidden = True
                            Range("C8:C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A6").EntireRow.Hidden = True
                        Range("A12:A18").EntireRow.Hidden = True
                        Range("A21").EntireRow.Hidden = True
                        Range("A33:A76").EntireRow.Hidden = True
                        If Range("M29") = False Then Rows("33:76").EntireRow.Hidden = True
                        End If
                        
                    Case "Hamburg to Los Angeles"
                        If rLoading.Value = "CFS Loading" Then          '   <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
                            Range("C19").EntireRow.Hidden = True
                            Range("C20").EntireRow.Hidden = False
                            Else
                            Range("C19").EntireRow.Hidden = False
                            Range("C20").EntireRow.Hidden = True
                        Range("C8:C10").Value = vbNullString
                        Range("C11:C17").Value = vbNullString
                        Range("C19:C21").Value = vbNullString
                        Range("D23:D25").Value = vbNullString
                        Range("A6").EntireRow.Hidden = True
                        Range("A12:A18").EntireRow.Hidden = True
                        Range("A21").EntireRow.Hidden = True
                        Range("A33:A76").EntireRow.Hidden = True
                        If Range("M29") = False Then Rows("33:76").EntireRow.Hidden = True
                        End If
    Regards

    Richard.
    Last edited by Scuba; 09-26-2023 at 03:33 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
  •