Results 1 to 6 of 6
  1. #1
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Passing Array Variables (XP; SR 3)

    I am trying to pass a variable into an array formula: The variable I would like to use is oCell = "A" & i & "". The variable oCell would replace A22 in the code below.

    For i = 22 To 48
    Range("A" & i & "") = "'" & i + 18
    Range("C" & i & "").FormulaArray = "=SUM((LEFT(AccountList!B2:B5000,2)= A22)*(AccountList!C2:C5000=""Dollars"")* _
    (AccountList!R2:R5000>=2000)*AccountList!Q2:Q5000) "
    Next i

    Thanks,
    Joihn

  2. #2
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Array Variables (XP; SR 3)

    Does this do what you want?

    <pre> For I = 22 To 48
    Range("A" & I) = "'" & I + 18
    Range("C" & I).FormulaArray = "=SUM((LEFT(AccountList!B2:B5000,2)= A" & I & ")*" & _
    "(AccountList!C2:C5000=""Dollars"")*(AccountList!R 2:R5000>=2000)*AccountList!Q2:Q5000)"
    Next I
    </pre>

    Legare Coleman

  3. #3
    3 Star Lounger Jim Cone's Avatar
    Join Date
    Feb 2002
    Location
    Portland, Oregon, USA
    Posts
    238
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Passing Array Variables (XP; SR 3)

    The following executes, but you will have to tell us if it is correct...
    '--------------------------
    Sub Test()
    Dim oCell As Double
    Dim i As Long
    For i = 22 To 48
    Cells(1, i).Value = i + 18
    oCell = Cells(1, i).Value
    Cells(3, i).FormulaArray = _
    "=SUM((LEFT(AccountList!B2:B5000,2)=" & oCell & ")*(AccountList!C2:C5000=""Dollars"")*(AccountList !R2:R5000>=2000)*AccountList!Q2:Q5000)"
    Next ' i
    Set oCell = Nothing
    End Sub
    '------------------------------

    Jim Cone
    San Francisco, CA

  4. #4
    Silver Lounger
    Join Date
    Dec 2000
    Location
    California, USA
    Posts
    1,758
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Array Variables (XP; SR 3)

    Legare,

    It does exactly what I want it to do.

    Thank,s
    John

  5. #5
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Passing Array Variables (XP; SR 3)

    Why does your code:

    <pre> Set oCell = Nothing
    </pre>


    oCell is defined as a Double, not an object variable.

    I also don't think the OP wanted the formula to compare to a constant value, I think he wanted to insert the cell address.
    Legare Coleman

  6. #6
    3 Star Lounger Jim Cone's Avatar
    Join Date
    Feb 2002
    Location
    Portland, Oregon, USA
    Posts
    238
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Passing Array Variables (XP; SR 3)

    Legare,
    The Set statement was a left over from my first try at the code.
    It shouldn't have been there.
    Regards,
    JimCone
    San Francisco, CA

Posting Permissions

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