I have a main sub that I am using to set up my worksheets and data for analysis in other subroutines. As part of this I am turning some imported data into a table(data was imported from a CSV file) and placed into "IncidentsData" worksheet. The code for the entire module compiles. However, when I step through the module I get "Run-Time Error '5': Invalid procedure call or argument" on the line where I format the imported data into a table at:
Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes).Name = "IncidentsDataTable"
Here is the overall subroutine:
Public Sub Categorise_Incidents()
Dim incidentsData1 As ListObject
Set Commodity = Worksheets("CommoditySheet").ListObjects("Table1")
Set QEListByGenus = Worksheets("QEListByGenus")
Set Results = Worksheets("Results")
Set IncidentsDataSheet = Worksheets("IncidentsData")
ISDRange = IncidentsDataSheet.UsedRange
Worksheets("IncidentsData").ListObjects.Add(xlSrcRange, ISDRange, , xlYes).Name = "IncidentsDataTable"
Set incidentsData1 = IncidentsDataSheet.ListObjects("IncidentsDataTable")
initialiseDictionaries
MainSearchLoop QEListByGenus, incidentsData1, dictQENSGenus
End Sub
I have gone to a number of sites to work out how to do this action including: 1. the stack overflow pages on runtime error 5 in excel vba - most of these seem to be specific to pivot tables and didn't tell me what I was doing wrong 2. https://msdn.microsoft.com/en-us/vba/excel-vba/articles/listobjects-object-excel 3. stack overflow questions on creating a table in VBA How to create a table using vba? 4. analysistabs on creating a table in excel vba https://analysistabs.com/excel-vba/tables-examples/ Plus a bunch of others. Unfortunately, they haven't helped me work out what I am doing wrong. Any help would be greatly appreciated. Cheers, S26
Edited: to include .Name as that also does not work and throws a runtime error and to fix typos/errors.
.Nameon the wrong line.Dim ISDRange as Rangeand thenSet ISDRange = ...