Excel VBA CSV export query

cerberus1845

New Member
Joined
Nov 14, 2023
Messages
23
Office Version
  1. 2021
Platform
  1. Windows
  2. MacOS
Hi,

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?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
ok - so i've thought about this,.., and think the cleanest/easiest solution would be to add a helper column in next to G - and then exclude G from the output?... unless anyone can suggest an alternative?
 
Upvote 0

Forum statistics

Threads
1,223,929
Messages
6,175,460
Members
452,644
Latest member
gjcase

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top