Consulting

Results 1 to 4 of 4

Thread: formulaArray resultat over Msgbox

  1. #1
    VBAX Regular
    Joined
    Jan 2011
    Posts
    55
    Location

    formulaArray resultat over Msgbox

    Dear Forum


    I am looking to pass the result of array formula to variable of other usage,
    for instance show the result as msgbox,

    is it Possible!!

    Thx in advance
    amrane
    Attached Files Attached Files

  2. #2
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Notice how I used s to build a string so I could debug in a test run to see if the Immediate window showed the correct string as used in the cell manually.

    Sub sample()
        Dim rg_1 As Range, rg_2 As Range
      Dim condit As String
      Dim result As Variant
      Dim s As String
      
      condit = "total"
      
      Set rg_1 = Sheets(1).Range(Cells(2, 4), Cells(Application.Rows.Count, 4).End(xlUp))
      Set rg_2 = Sheets(1).Range(Cells(2, 5), Cells(Application.Rows.Count, 5).End(xlUp))
      
      s = "=AVERAGE(IF(" & rg_1.Address(False, False) & "=B2," & rg_2.Address(False, False) & "))"
      Debug.Print s
      '=AVERAGE(IF(D2:D28=B2,E2:E28))
      result = MsgBox(Evaluate(s))
    
    
      MsgBox Sheet1.Range("C2")
    End Sub

  3. #3
    VBAX Regular
    Joined
    Jan 2011
    Posts
    55
    Location
    Dear Mr Kenneth Hobs

    its perfect your solution, Thx, Thx a lot, you're solving big headache

    amrane

  4. #4
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,645
    An alternatvie approach:

    Sub M_snb()
       sn = Sheet1.UsedRange.Columns(4).Resize(, 2)
    
       For j = 1 To UBound(sn)
         If sn(j, 1) = Cells(2, 2) Then
           y = y + sn(j, 2)
           x = x + 1
         End If
       Next
       
       msgbox y / x
    End Sub

Posting Permissions

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