C
Chechu
I have the following macro:
Sub tracking()
engid = "'[Export January.xls]Export_January'!$aq$2:$aq$43735"
rev = "'[Export January.xls]Export_January'!$ag$2:$ag$43735"
engid2 = Sheets("actual").Range("H4").Value
If Not IsNumeric(engid2) Then
engid2 = """" & engid2 & """"
End If
pct = Application.Evaluate("SUMPRODUCT(--(" & engid & "=" _
& engid2 & "),--(" & rev & "))")
ThisWorkbook.Worksheets("actual").Range("AL12").Select
Range("al12").Value = pct
End Sub
It works OK but, source file is hard coded. What I want to do is to
allow the user to select the source file, and probably open the file
(sumproduct in VBA works with closed files??? I don’t think so). I
know I should include something like:
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
..AllowMultiSelect = False
If .Show = -1 Then
Set sourcebook = Workbooks.Open(Filename:=fd.SelectedItems(1))
With sourcebook….???????
……..But how to assign to a variable the file name for the selected
file, and also, how to modify the sumproduct syntax to use it???
Thanks,
Cecilia
Sub tracking()
engid = "'[Export January.xls]Export_January'!$aq$2:$aq$43735"
rev = "'[Export January.xls]Export_January'!$ag$2:$ag$43735"
engid2 = Sheets("actual").Range("H4").Value
If Not IsNumeric(engid2) Then
engid2 = """" & engid2 & """"
End If
pct = Application.Evaluate("SUMPRODUCT(--(" & engid & "=" _
& engid2 & "),--(" & rev & "))")
ThisWorkbook.Worksheets("actual").Range("AL12").Select
Range("al12").Value = pct
End Sub
It works OK but, source file is hard coded. What I want to do is to
allow the user to select the source file, and probably open the file
(sumproduct in VBA works with closed files??? I don’t think so). I
know I should include something like:
Set fd = Application.FileDialog(msoFileDialogOpen)
With fd
..AllowMultiSelect = False
If .Show = -1 Then
Set sourcebook = Workbooks.Open(Filename:=fd.SelectedItems(1))
With sourcebook….???????
……..But how to assign to a variable the file name for the selected
file, and also, how to modify the sumproduct syntax to use it???
Thanks,
Cecilia