Timely insight needed!
Attempting to setup a MS Excel workbook template that contains several Excel tables.
The file is to be used weekly to review and analyze data for 8 departments. In essence, the various departments place text files on the network drive and I retrieve them and analyze using the template and then save the MS Excel file (without the complex formulae) for the departments' use.
The plan is to import the text file for a particular department into worksheet 1 and convert the active range to a table. Then, the tables on the other worksheets, Sheets2 through 10, that contain formulae involving the sumproduct function are dynamically populated. The analysis is performed and then, I import the text file for the other department and perform the analysis. And so on...until all of the departments are analyzed.
It appears that it is necessary to import the text file into a worksheet so that I can use the sumproduct function within the formulae.
Is this correct? Are there any viable alternatives? In other words, I don't believe that the sumproduct can be used within an Excel table to extract data from MS Access or a data model within PowerPivot. Example of sumproduct in use include "=SUMPRODUCT((tMSTR[ExpenseType]=$B8)*(tMSTR[Month]=C$7)*(tMSTR[Year]=$B$1)*(tMSTR[PaidAmt]))."
Currently, I have an error --> "Invalid Procedure call or argument."
How should this error, within the following code, be resolved? Also, any additional insight regarding the feasibility of the planned setup is appreciated. Would you perform this differently?
Attempting to setup a MS Excel workbook template that contains several Excel tables.
The file is to be used weekly to review and analyze data for 8 departments. In essence, the various departments place text files on the network drive and I retrieve them and analyze using the template and then save the MS Excel file (without the complex formulae) for the departments' use.
The plan is to import the text file for a particular department into worksheet 1 and convert the active range to a table. Then, the tables on the other worksheets, Sheets2 through 10, that contain formulae involving the sumproduct function are dynamically populated. The analysis is performed and then, I import the text file for the other department and perform the analysis. And so on...until all of the departments are analyzed.
It appears that it is necessary to import the text file into a worksheet so that I can use the sumproduct function within the formulae.
Is this correct? Are there any viable alternatives? In other words, I don't believe that the sumproduct can be used within an Excel table to extract data from MS Access or a data model within PowerPivot. Example of sumproduct in use include "=SUMPRODUCT((tMSTR[ExpenseType]=$B8)*(tMSTR[Month]=C$7)*(tMSTR[Year]=$B$1)*(tMSTR[PaidAmt]))."
Currently, I have an error --> "Invalid Procedure call or argument."
How should this error, within the following code, be resolved? Also, any additional insight regarding the feasibility of the planned setup is appreciated. Would you perform this differently?
Code:
Sub mcrManuallyImportTextFile()
Dim txtFileNameAndPath As String
Dim ImportingFileName As String
Dim fd As Office.FileDialog
Dim SheetName As Worksheet
Set fd = Application.FileDialog(msoFileDialogFilePicker)
With fd
.AllowMultiSelect = False
.Title = "Please select the file."
.Filters.Clear
.Filters.Add "txt", "*.txt"
.Filters.Add "All Files", "*.*"
If .Show = True Then
txtFileNameAndPath = .SelectedItems(1)
Else
MsgBox "Please start over. You must select a file to import"
Exit Sub
End If
End With
With ActiveWorkbook.Connections("SampleTextFile4a")
.Name = "SampleTextFile4a"
.Description = ""
End With
Workbooks("Book1").Connections.AddFromFile _
"C:\Users\Bill\Documents\SampleTextFile4a.txt", True, False
'*********************************************************************
'' 4/3/2016 at 4:40 pm Error at the line below ----> Invalid procedure call or argument
'*********************************************************************
With ActiveSheet.ListObjects.Add(SourceType:=4, Source:=ActiveWorkbook. _
Connections("SampleTextFile4a"), Destination:=Range("$A$1")).TableObject
.RowNumbers = False
.PreserveFormatting = True
.RefreshStyle = 1
.AdjustColumnWidth = True
.ListObject.DisplayName = "Table_SampleTextFile4a"
.Refresh
End With
ActiveWorkbook.Names.Add Name:="tMSTR", RefersToR1C1:= _
"=Table_SampleTextFile4a[#All]"
End Sub