I am trying to export a particular range of cells from a worksheet to notepad. I need everything from columns A to AH, row 4 to the last row with data in column A. I have the following code so far but my issues are:
1. Need the file saved to a particular path (default file path won’t work).
2. Want to name the txt file whatever is located in cell B2 of the spreadsheet.
3. The notepad file currently has ” ” around each line of information and that won’t work for what I’m attempting to do.
4. Instead of comma delimited, is there a way to make this tab delimited?
5. It’s pulling over additional rows (some columns have IF formulas all the way down). I need the file to stop exporting when it gets to the last entered cell in column A.
Sub WriteTextFile()
Dim FilePath As String
Dim CellData As String
Dim LastCol As Long
Dim LastRow As Long
LastRow = ActiveSheet.UsedRange.SpecialCells(xlCellTypeLastCell).Row
FilePath = Application.DefaultFilePath & “EZB_UPLOAD.txt”
Open FilePath For Output As #2
For i = 4 To LastRow
For j = 1 To 34
If j = 34 Then
CellData = CellData + Trim(ActiveCell(i, j).Value)
Else
CellData = CellData + Trim(ActiveCell(i, j).Value) + “,”
End If
Next j
Write #2, CellData
CellData = “”
Next i
Close #2
MsgBox (“Run Job Scheduler”)
End Sub
Any modifications/suggestions would be great! I’m very new to macros.