For some reason I am getting a lot of spaces in front of each value while trying to print to a flat text file.
'append headers
Cells(start_row - 2, 1).Select
For i = 1 To ActiveCell.SpecialCells(xlLastCell).Column
If ActiveCell.Offset(0, 1).Column = Activ开发者_如何学CeCell.SpecialCells(xlLastCell).Column Then
Print #finalCSV, Cells(start_row - 2, i) & "\n",
Else
Print #finalCSV, Cells(start_row - 2, i) & ",",
End If
Next i
Example output:
DC Capacity:hi, Resistive Capacity:lo, Resistive Capacity:hi, Reactive Capacity:lo,
Is there any way to get rid of these spaces?
Print #finalCSV, Cells(start_row - 2, i) & ",";
If I remember my VB correctly, a comma inserts a tab, while a semicolon just suppresses the newline.
Print #finalCSV, Trim(Cells(start_row - 2, i)) & ",",
Vincent's answer is right but I want to make it even more clear:
Print #finalCSV, Cells(start_row - 2, i) & ",",
will give this kind of output:
> DC Capacity:hi, Resistive Capacity:lo, Resistive
> Capacity:hi, Reactive Capacity:lo,
and using semicolon at the end of the sentence:
Print #finalCSV, Cells(start_row - 2, i) & ",";
will give you this output:
> DC Capacity:hi,Resistive Capacity:lo,Resistive Capacity:hi,Reactive
> Capacity:lo,
精彩评论