需要您的帮助,以删除额外的尾随逗号这是越来越当我创建一个CSV文件使用宏生成
下面是我用来创建CSV文件,我尝试了各种选项,但它不工作,请帮助
Sub NEWMACRO ()
Dim complete_rec As String
mylogfile = FreeFile()
Dim rng As Range
Dim lLastRow As Integer
Dim lLastCol As Integer
Open "C:\File\ Range("A2").Value & ".csv" For Output Access Write As mylogfile
Set rng = Range("A1").SpecialCells(xlCellTypeLastCell)
lLastRow = rng.Row
lLastCol = rng.Column
For irow = 1 To lLastRow
For icol = 1 To lLastCol
If icol = 1 Then
complete_rec = Application.Cells(irow, icol).Value
Else
complete_rec = complete_rec & "," & Application.Cells(irow, icol).Value
End If
Next icol
complete_rec = complete_rec + " "
Print #mylogfile, complete_rec
Next irow
Close mylogfile
End Sub
1条答案
按热度按时间jyztefdp1#
如果您不希望这些尾随逗号,那么您需要读取每一行,直到该行的最后一个值,而不是假设所有行都有相同的结束点。
这里有一个你可以使用的方法: