idlewyld89
New Member
- Joined
- Jun 10, 2018
- Messages
- 23
Alright, so I've got a bit of an odd outcome from this bit of code... It works, but only under specific circumstances.
If I run the code on a fresh file (where the table "FleetStatusDetail" doesn't exist and HAS NEVER EXISTED) I get a Runtime Error 438. HOWEVER, if I comment out the IF statement (thereby forcing table creation without testing) and then run the exact same code with the IF statement back in, it works without error. The IF statement recognizes the existence of the table and ignores the line of code to create it again.
I should also say that, if I delete the sheet and copy back in the raw data (not formatted as a table) the code will also identify the non-existence of the table and create it as intended.
It seems that it's ONLY if I run the code on a completely fresh file that it generates this error... and I'm stumped!!!
Pertinent info:
- "FleetStatusDetail" is the name of the table which I am testing the existence of, and if nonexistent, creating
If I run the code on a fresh file (where the table "FleetStatusDetail" doesn't exist and HAS NEVER EXISTED) I get a Runtime Error 438. HOWEVER, if I comment out the IF statement (thereby forcing table creation without testing) and then run the exact same code with the IF statement back in, it works without error. The IF statement recognizes the existence of the table and ignores the line of code to create it again.
I should also say that, if I delete the sheet and copy back in the raw data (not formatted as a table) the code will also identify the non-existence of the table and create it as intended.
It seems that it's ONLY if I run the code on a completely fresh file that it generates this error... and I'm stumped!!!
Code:
Private Sub convert_DataToTable()
' References:
' Dependents:
' ~~> Converts the active sheet's dataset to a table (if it is not already formatted as a table)
If ActiveSheet.ListObject("FleetStatusDetail") Is Nothing Then
ActiveSheet.ListObjects.Add(SourceType:=xlSrcRange, Source:=Range("A1").CurrentRegion, LinkSource:=False, xlListObjectHasHeaders:=xlYes, TableStyleName:="TableStyleLight1").Name = "FleetStatusDetail"
End If
End Sub
Pertinent info:
- "FleetStatusDetail" is the name of the table which I am testing the existence of, and if nonexistent, creating