ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Text Export macro modification? (https://www.excelbanter.com/excel-programming/426367-text-export-macro-modification.html)

dk

Text Export macro modification?
 
I'm exporting text to an application that requires that when a field is
empty there should be nothing between the seperators for that field. Clear
as mud?
When Field3 is empty, my text file needs to read; fld1,fld2,,fld4,fld5...
I'm using a wonderful macro from Chip Pearson at
http://www.cpearson.com/excel/ImpText.aspx
However, my empty fields end up in the text file as fld1,fld2,"",fld4,fld5
Below is part of the macro. How can I modify the code leave the field
"empty" (without the quotes)?
Thanks.

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx



FSt1

Text Export macro modification?
 
hi,
this line
CellValue = Chr(34) & Chr(34)
chr(34) is a double quote(") so the macro itself is putting the quotes in.
try this..
CellValue = ""
and see what happens.

Regards
FSt1

"DK" wrote:

I'm exporting text to an application that requires that when a field is
empty there should be nothing between the seperators for that field. Clear
as mud?
When Field3 is empty, my text file needs to read; fld1,fld2,,fld4,fld5...
I'm using a wonderful macro from Chip Pearson at
http://www.cpearson.com/excel/ImpText.aspx
However, my empty fields end up in the text file as fld1,fld2,"",fld4,fld5
Below is part of the macro. How can I modify the code leave the field
"empty" (without the quotes)?
Thanks.

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx




dk

Text Export macro modification?
 
That did it!
Thanks very much.
DK

"FSt1" wrote in message
...
hi,
this line
CellValue = Chr(34) & Chr(34)
chr(34) is a double quote(") so the macro itself is putting the quotes in.
try this..
CellValue = ""
and see what happens.

Regards
FSt1

"DK" wrote:

I'm exporting text to an application that requires that when a field is
empty there should be nothing between the seperators for that field.
Clear
as mud?
When Field3 is empty, my text file needs to read;
fld1,fld2,,fld4,fld5...
I'm using a wonderful macro from Chip Pearson at
http://www.cpearson.com/excel/ImpText.aspx
However, my empty fields end up in the text file as
fld1,fld2,"",fld4,fld5
Below is part of the macro. How can I modify the code leave the field
"empty" (without the quotes)?
Thanks.

For RowNdx = StartRow To EndRow
WholeLine = ""
For ColNdx = StartCol To EndCol
If Cells(RowNdx, ColNdx).Value = "" Then
CellValue = Chr(34) & Chr(34)
Else
CellValue = Cells(RowNdx, ColNdx).Text
End If
WholeLine = WholeLine & CellValue & Sep
Next ColNdx
WholeLine = Left(WholeLine, Len(WholeLine) - Len(Sep))
Print #FNum, WholeLine
Next RowNdx







All times are GMT +1. The time now is 05:42 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com