oscarmiike
New Member
- Joined
- Apr 24, 2018
- Messages
- 3
Hi all,
I've got the code below from the microsoft support website https://support.microsoft.com/en-us...t-file-with-both-comma-and-quote-delimiters-i
The problem is it's working a little too well. I only need the First Row of the columns (basically the table headers) with the "" qualifier. The code below applied the "" to all cells.
I don't know how to make this change. Any help would be greatly appreciated!
Many thanks!
OM.
I've got the code below from the microsoft support website https://support.microsoft.com/en-us...t-file-with-both-comma-and-quote-delimiters-i
The problem is it's working a little too well. I only need the First Row of the columns (basically the table headers) with the "" qualifier. The code below applied the "" to all cells.
I don't know how to make this change. Any help would be greatly appreciated!
Code:
Sub QuoteCommaExport()
' Dimension all variables.
Dim DestFile As String
Dim FileNum As Integer
Dim ColumnCount As Integer
Dim RowCount As Integer
' Prompt user for destination file name.
DestFile = InputBox("Enter the destination filename" _
& Chr(10) & "(with complete path):", "Quote-Comma Exporter")
' Obtain next free file handle number.
FileNum = FreeFile()
' Turn error checking off.
On Error Resume Next
' Attempt to open destination file for output.
Open DestFile For Output As [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL]
' If an error occurs report it and end.
If Err <> 0 Then
MsgBox "Cannot open filename " & DestFile
End
End If
' Turn error checking on.
On Error GoTo 0
' Loop for each row in selection.
For RowCount = 1 To Selection.Rows.Count
' Loop for each column in selection.
For ColumnCount = 1 To Selection.Columns.Count
' Write current cell's text to file with quotation marks.
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL] , """" & Selection.Cells(RowCount, _
ColumnCount).Text & """";
' Check if cell is in last column.
If ColumnCount = Selection.Columns.Count Then
' If so, then write a blank line.
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL] ,
Else
' Otherwise, write a comma.
Print [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL] , ",";
End If
' Start next iteration of ColumnCount loop.
Next ColumnCount
' Start next iteration of RowCount loop.
Next RowCount
' Close destination file.
Close [URL=https://www.mrexcel.com/forum/usertag.php?do=list&action=hash&hash=FileNum]#FileNum[/URL]
End Sub
Many thanks!
OM.