I have an excel sheet with many columns and an unknown number of rows. I'm trying to write a VB macro to dynamically convert the data from a few selected columns and all rows into a table.
I'm running into some syntaxt issues. Everything I find says to use the As
syntax. For example:
Dim workRow As DataRow = table.NewRow()
or
Dim table As New DataTable
But whenever I do this I get an error Expected: End of statement
Here is my code:
Sub CreateTable()
FinalRow = Cells(Rows.Count, 6).End(xlUp).Row
Dim table
table = DataTable("TotOpenOI")
Dim strike
strike = DataColumn("Strike", GetType(Int32))
Dim expiry
expiry = DataColumn("Expiry", GetType(DateTime))
Dim callDelta
callDelta = DataColumn("Call Delta", GetType(Int32))
Dim putDelta
putDelta = DataColumn("Put Delta", GetType(Int32))
Dim tableRow
For i = 6 To FinalRow
tableRow = DataRow.NewRow()
tableRow(0) = strike
tableRow(1) = expiry
tableRow(2) = callDelta
tableRow(3) = putDelta
table.Rows.Add (tableRow)
Next
End Sub
I want to create a new table with the columns: strike, expiry, callDelta, PutDelta and use every row from 1 to last -- starts at row 6.
Note: I'm only using those 4 columns but there are 20 or so columns in my spreadsheet.
Thank you.
My goal is to create a pivot table out of the columns I highlighted in my original question. The data I'm pulling in has a lot of columns I don't need and the API doesn't allow me to remove columns in the query. So I want to create a new, more condensed table out of the data to then use to create a pivot table. I added a screen shot of the chart I'm creating from the selected data.
Export Columns to a New Excel Table