cerberus1845
New Member
- Joined
- Nov 14, 2023
- Messages
- 23
- Office Version
- 2021
- Platform
- Windows
- MacOS
Hi,
I have the following code which works well:
The issue I have is that the source table (table2) has some data in it that is currently included in the export which I want to remove (replace with blank/null values) but retain the information in those rows and the rest of the table.
I want to specifically exclude the values in G2:G29 - or for these to be blank/null in the export only (the values till have to be retained in the table) - does anyone know if this is possible and how I'd go about achieving this?
I have the following code which works well:
VBA Code:
'CODE TO PRODUCE CSV OUTPUT FILE
Sub saveTableToCSV()
MsgBox "Press OK to confirm export and please be patient...", vbInformation
Application.DisplayAlerts = False
Dim tbl As ListObject
Dim csvFilePath As String
Dim fNum As Integer
Dim tblArr
Dim rowArr
Dim csvVal
Set tbl = Worksheets("RecruiterAllocation").ListObjects("table2")
'LOCAL OUTPUT DETAILS
csvFilePath = ThisWorkbook.Path & "\Primary Recruiter Output File_" & Format(Now(), "YYYYMMDD hhmmss") & ".csv"
'SPECIFY WHICH COLUMNS TO EXPORT
tblArr = tbl.Range.Columns("B:L").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
Application.DisplayAlerts = True
MsgBox "Export Completed Succesfully! - Output file location:" & vbNewLine & csvFilePath, vbInformation
End Sub
The issue I have is that the source table (table2) has some data in it that is currently included in the export which I want to remove (replace with blank/null values) but retain the information in those rows and the rest of the table.
I want to specifically exclude the values in G2:G29 - or for these to be blank/null in the export only (the values till have to be retained in the table) - does anyone know if this is possible and how I'd go about achieving this?