Consulting

Results 1 to 3 of 3

Thread: the remove method in Collection and Select Case

  1. #1
    VBAX Regular
    Joined
    Sep 2017
    Posts
    16
    Location

    Smile the remove method in Collection and Select Case

    Hi VBA Experts!

    I coded to extract and load tables for each instrument ( Cash, Stock, Bond, Option, CDS) showing its value as well as the total portfolio value for the same date.(highlighted in Blue)
    Now, I need to make 5 different scenario tables for each instrument, filling the yellow highlighted areas as in the below screen shot for each Scenario.
    For example, Scenario 1 is the combination of Stock, Bond, Option and CDS (but, No Cash), which equals to the total Total Portfolio minus cash.
    Capture4.PNG

    I want to use the remove method in Collection and Select, Case statement as below. But, the remove statement in the Sub TestGetPortfolioValue() below doesn't work
    Please share with me if there is better way to do this.
    (I put the range reference as Sceario1, Scenario2, Scenario3, Scenario4, Scenario 5 where I would like load the data in a spreadsheet.)
    .
    Select Case
        Case is newPort.Der.Remove "cash"
            For i = 1 To 10
                Range("scenario1").Cells(i, 1) = newPort.GetTotal(Range("Scenario1").Cells(i, 1))
            Next i
        Case is newPort.Der.Remove "Stock"
            For i = 1 To 10
                Range("scenario2").Cells(i, 1) = newPort.GetTotal(Range("Scenario2").Cells(i, 1))
            Next i
        Case is newPort.Der.Remove "Bond"
            For i = 1 To 10
                Range("scenario3").Cells(i, 1) = newPort.GetTotal(Range("Scenario3").Cells(i, 1))
            Next i
        Case is newPort.Der.Remove "Option"
            For i = 1 To 10
                Range("scenario4").Cells(i, 1) = newPort.GetTotal(Range("Scenario4").Cells(i, 1))
            Next i
        Case is newPort.Der.Remove "CDS"
            For i = 1 To 10
                Range("scenario5").Cells(i, 1) = newPort.GetTotal(Range("Scenario5").Cells(i, 1))
            Next i
    End Select


    Anyone of you can enlighten me?

    Any help is greatly appreciated.

    Regards,
    Demian
    Attached Files Attached Files

  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,728
    Location
    1. Select Case works by using a 'value' (Newport.Der below) and matching it with a Case selector (Case Is "cash") and then executing the statements that are part of the selected Case

    2. I don't know where or why you wanted the .Remove

    3. If you want Stock + Bond + Option + CDS (no Cash) then you need to add those four

    4. the Select Case is case-sensitive, so if the data is "Cash" then "cash" will not match


    Select Case  newPort.Der
    
        Case Is "cash" 
            For i = 1 To 10 
                Range("scenario1").Cells(i, 1) = newPort.GetTotal(Range("Scenario1").Cells(i, 1)) 
            Next i 
    
    
    
    ...etc.
    
    
    
    
    
    End Select
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Regular
    Joined
    Sep 2017
    Posts
    16
    Location
    Many Thanks, Paul!

Posting Permissions

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