Self_Taught
New Member
- Joined
- Nov 20, 2013
- Messages
- 6
I'm attempting to output data from Excel into a tab delimited text file. I've used this macro successfully before but in this case the users have data that displays as a percentage in Column 4. e.g. value is 73.3%.
When I run this code against it the text file created displays the value as 0.733. How can I get this to output "73.3%"?
Here is my code:
Sub format_txt_col(Control As IRibbonControl)
'label columns
Cells(3, 1).Value = "Municode"
Cells(3, 3).Value = "LG_Custom1"
Cells(3, 4).Value = "LG_Custom2"
Cells(3, 5).Value = "LG_Custom3"
Cells(3, 6).Value = "LG_Custom4"
Cells(3, 7).Value = "LG_Custom5"
'save as tab delimetd text file
ImportFile = "H:\Import on " & Month(Date) & "-" & Day(Date) & _
"-" & Year(Date) & ".txt"
'deletes old copy
On Error Resume Next
Kill (ImportFile)
On Error GoTo 0
'Open new file
Open ImportFile For Output As #1
FinalRow = Range("A654536").End(xlUp).Row
'write to file
For j = 3 To FinalRow
Print #1, Cells(j, 1).Value & Chr(9) & Cells(j, 3).Value & Chr(9) & Cells(j, 4).Value & Chr(9) & Cells(j, 5).Value & Chr(9) & Cells(j, 6).Value & Chr(9) & Cells(j, 7).Value
Next j
'close workbook and notify user where file is located
MyMsg = "A file named Import on <today> has been created on your H drive. This workbook will now close."
response = MsgBox(MyMsg, vbOKOnly, "Closing Workbook")
Select Case response
Case Is = vbOK
ActiveWorkbook.Close (False)
End Select
End Sub
When I run this code against it the text file created displays the value as 0.733. How can I get this to output "73.3%"?
Here is my code:
Sub format_txt_col(Control As IRibbonControl)
'label columns
Cells(3, 1).Value = "Municode"
Cells(3, 3).Value = "LG_Custom1"
Cells(3, 4).Value = "LG_Custom2"
Cells(3, 5).Value = "LG_Custom3"
Cells(3, 6).Value = "LG_Custom4"
Cells(3, 7).Value = "LG_Custom5"
'save as tab delimetd text file
ImportFile = "H:\Import on " & Month(Date) & "-" & Day(Date) & _
"-" & Year(Date) & ".txt"
'deletes old copy
On Error Resume Next
Kill (ImportFile)
On Error GoTo 0
'Open new file
Open ImportFile For Output As #1
FinalRow = Range("A654536").End(xlUp).Row
'write to file
For j = 3 To FinalRow
Print #1, Cells(j, 1).Value & Chr(9) & Cells(j, 3).Value & Chr(9) & Cells(j, 4).Value & Chr(9) & Cells(j, 5).Value & Chr(9) & Cells(j, 6).Value & Chr(9) & Cells(j, 7).Value
Next j
'close workbook and notify user where file is located
MyMsg = "A file named Import on <today> has been created on your H drive. This workbook will now close."
response = MsgBox(MyMsg, vbOKOnly, "Closing Workbook")
Select Case response
Case Is = vbOK
ActiveWorkbook.Close (False)
End Select
End Sub