embed alignment in csv file

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Does anyone know if there is a way to embed the alignment in a csv file so
that it aligns correctly when I open it in excel?
For instance If I create a csv file with '""01234""' the column will open as
an text field. I was hoping to do something like the same with aligning left
or right.
THank you,
 
A CSV file only contains data, no formatting information. Excel will use the
general format for each column (texts are aligned left, numbers are aligned
right). What you could do is to have the first row of your file with the
alignment you need for each column, then run a short macro that would perform
alignment according to the instructions.

Sub AlignColumns()
' Align columns according to the text
' "left", "right", "center" in the first row

Dim i As Long

For i = 1 To 255
Select Case LCase(Cells(1, i))
Case "left"
Columns(i).HorizontalAlignment = xlLeft
Case "right"
Columns(i).HorizontalAlignment = xlRight
Case "center"
Columns(i).HorizontalAlignment = xlCenter
End Select
Next i

End Sub
 
Back
Top