Re: SumProduct in VBA - Allow the user to select the file



Chechu wrote:
On Jan 31, 9:52 pm, keiji kounoike <"kounoike A | T ma.Pikara.ne.jp">
wrote:


Keiji, THANKS a lot. I received an error 13, Type Mismatch, in the
line MsgBox "Sum of arg1 is " & Application.Sum(arg1)
The msgbox to show value on H4 works OK, shows the value (without
quotes).
Any idea where could be the issue?? I am completely missed...
Thanks!!
Cecilia

That's because the array arg1 has error values in it. You said when I type the formula directly in Excel with the same arguments, it works OK. so, the macro below put a formula equivalent to Sumproduct(arg1,arg2) instead of value. then, check that formula comparing with the formula typed directly in Excel.

Sub tracking_test2()
Const ad1 = "$aq$2:$aq$43735"
Const ad2 = "$ag$2:$ag$43735"
Const ad3 = "H4"
Dim Acwk As Workbook, Tarwk As Workbook
Dim fname As String, shname As String
Dim arg1, arg2

Application.ScreenUpdating = False
Application.DisplayAlerts = False
Set Acwk = ActiveWorkbook

If Not Application.Dialogs(xlDialogOpen).Show Then
Exit Sub
End If

Set Tarwk = ActiveWorkbook
fname = Tarwk.Name
shname = Tarwk.Worksheets(1).Name
Acwk.Activate
Worksheets("tracking").Select

'arg1 = Application.Evaluate("--([" & fname & "]" & shname & "!" & _
ad1 & " = " & ad3 & ")")

'arg2 = Application.Evaluate("--([" & fname & "]" & shname & "!" & _
ad2 & ")")

'Range("al12") = Application.SumProduct(arg1, arg2)

Range("al12").Formula = _
"=SumProduct(" & "--([" & fname & "]" & shname & "!" & ad1 & _
" = " & ad3 & "), --([" & fname & "]" & shname & "!" & ad2 & "))"

'Tarwk.Close

End Sub

Keiji
.



Relevant Pages

  • Re: Excel 2003 Macro
    ... Private Sub Auto_Open ... Dim CalcMode As Long ... Dim WSNew As Worksheet ... If SheetExists("Spring '07", ActiveWorkbook) = True Then ...
    (microsoft.public.excel.worksheet.functions)
  • Re: Multiple Files to Import
    ... set NewB = Workbooks.OpenText ... If = vbBoolean) Then Exit Sub ... Dim Newb As Workbook ... Set b = ActiveWorkbook ...
    (microsoft.public.excel.programming)
  • Re: Input Box Promt
    ... Sub Test() ... Dim Filename As Variant ... This example will save a copy of the activeworkbook ... Dim fname As Variant ...
    (microsoft.public.excel.programming)
  • Re: Input Box Promt
    ... Sub Test() ... Dim Filename As Variant ... This example will save a copy of the activeworkbook ... Dim fname As Variant ...
    (microsoft.public.excel.programming)
  • RE: Email Sheet
    ... Dim wb As Workbook ... Set wb = ActiveWorkbook ... Private Sub Worksheet_Activate ...
    (microsoft.public.excel.programming)