views:

45

answers:

2

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 = ActiveCell.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?

+1  A: 
Print #finalCSV, Trim(Cells(start_row - 2, i)) & ",",
Simon Chadwick
+2  A: 
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.

Vincent
I think it was also true in B pre-V...
jtolle