cerberus1845
New Member
- Joined
- Nov 14, 2023
- Messages
- 23
- Office Version
- 2021
- Platform
- Windows
- MacOS
Hi,
I've found the following code:
Does anyone know how I would edit the above to not output the entire table - but instead all data in columns B to L?? - I've tried tweaking it - but can't seem to get it to work...
I've found the following code:
VBA Code:
Sub saveTableToCSV()
Dim tbl As ListObject
Dim csvFilePath As String
Dim fNum As Integer
Dim tblArr
Dim rowArr
Dim csvVal
Set tbl = Worksheets("YourSheetName").ListObjects("YourTableName")
csvFilePath = "C:\Users\vmishra\Desktop\CSVFile.csv"
tblArr = tbl.DataBodyRange.Value
fNum = FreeFile()
Open csvFilePath For Output As #fNum
For i = 1 To UBound(tblArr)
rowArr = Application.Index(tblArr, i, 0)
csvVal = VBA.Join(rowArr, ",")
Print #1, csvVal
Next
Close #fNum
Set tblArr = Nothing
Set rowArr = Nothing
Set csvVal = Nothing
End Sub
Does anyone know how I would edit the above to not output the entire table - but instead all data in columns B to L?? - I've tried tweaking it - but can't seem to get it to work...