• Passing Array Variables (XP; SR 3)

    Author
    Topic
    #413209

    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

    Viewing 2 reply threads
    Author
    Replies
    • #909705

      Does this do what you want?

          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!R2:R5000>=2000)*AccountList!Q2:Q5000)"
          Next I
      
      • #909712

        Legare,

        It does exactly what I want it to do.

        Thank,s
        John

      • #909713

        Legare,

        It does exactly what I want it to do.

        Thank,s
        John

    • #909706

      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

      • #909714

        Why does your code:

            Set oCell = Nothing
        

        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.

        • #909719

          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

        • #909720

          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

      • #909715

        Why does your code:

            Set oCell = Nothing
        

        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.

    • #909707

      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

    Viewing 2 reply threads
    Reply To: Passing Array Variables (XP; SR 3)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: