RockinBill
New Member
- Joined
- Apr 29, 2009
- Messages
- 1
My first time posting. I need help to create a text file from Excel that can be imported into my Accounting system which requires a fixed length records. I am having trouble outputting the number fields in the correct format. These number fields must be 12 positions of which 2 are decimal places but the output can not contain a decimal point. The source data will have a zero, one decimal place or many decimal places. The output (printed) field must be right justified and padded with spaces.
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com
ffice
ffice" /><o
></o
>
0 must end up 1 or more zeros mine moves 2 spaces to right 510.00 must end up 51000 mine moves 3 to the right
1610.5 must end up 161050 mine moves 1 space to right
1001.517 must end up 100152 100151.7 mine moves 1 and adds decimal
<o
></o
>
Here is my code so far. I inserted a ' and line number to make it easer to view here. Lines 12 and 13 are the ones not working correctly.
<o
></o
>
'1 Sub MakeFixedWidth()
'2 Dim MyStr As String, PageName As String, FirstRow As Integer, LastRow As Integer, MyRow As Integer
'3 PageName = "C:\JE Upload" & Format(Time, "HHMMSS") & ".txt" 'location and name of saved file
'4 FirstRow = Range("H1").Value 'the range of the table to be exported
'5 LastRow = FirstRow + Range("H2").Value - 1
'6 Open PageName For Output As #2
'7 Print #2, "01" & Format(Date, "yyyymmdd") & "GL TRANSACTIONS UPLOADED " & Format(Date, "yyyymmdd") & " " & Format(Time, "HHMMSS") '01 record RT-2, Create date, FILE ID LEN(35)
'8 Print #2, "05" & "BATCH " & Range("E11") & String(24 - Len(Range("E11")), " ") & Format(Date, "yyyymmdd") & Range("g10") & Range("a5") 'batch header rt-2,Btch ID-30,Btch Dt, post to dt,journal name
'9 For MyRow = FirstRow To LastRow 'loop through each row of the table
'10 MyStr = ""
'11 MyStr = "10" & Cells(MyRow, 1).Value & String(25 - Len(Cells(MyRow, 1).Value), " ") 'Rec type + GL account number
'12 MyStr = MyStr & String(12 - Len(Cells(MyRow, 5).Value numberformat=###.00), " ") & Cells(MyRow, 5).Value * 100 'Debit amount
'13 MyStr = MyStr & String(12 - Len(Cells(MyRow, 6).Value), " ") & Cells(MyRow, 6).Value * 100 'Credit amount
'14 Print #2, MyStr
'15 Next
'16 Print #2, "99" ' MyTrailer
'17 Close #2
'18 Sheets("JE Upload").Range("F2").ClearContents ' note that this row expects the worksheet to be named JE Upload
'19 Sheets("JE Upload").Hyperlinks.Add Range("F2"), PageName
'20 End Sub<o
></o
>
<o
></o
>
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com




0 must end up 1 or more zeros mine moves 2 spaces to right 510.00 must end up 51000 mine moves 3 to the right
1610.5 must end up 161050 mine moves 1 space to right
1001.517 must end up 100152 100151.7 mine moves 1 and adds decimal
<o


Here is my code so far. I inserted a ' and line number to make it easer to view here. Lines 12 and 13 are the ones not working correctly.
<o


'1 Sub MakeFixedWidth()
'2 Dim MyStr As String, PageName As String, FirstRow As Integer, LastRow As Integer, MyRow As Integer
'3 PageName = "C:\JE Upload" & Format(Time, "HHMMSS") & ".txt" 'location and name of saved file
'4 FirstRow = Range("H1").Value 'the range of the table to be exported
'5 LastRow = FirstRow + Range("H2").Value - 1
'6 Open PageName For Output As #2
'7 Print #2, "01" & Format(Date, "yyyymmdd") & "GL TRANSACTIONS UPLOADED " & Format(Date, "yyyymmdd") & " " & Format(Time, "HHMMSS") '01 record RT-2, Create date, FILE ID LEN(35)
'8 Print #2, "05" & "BATCH " & Range("E11") & String(24 - Len(Range("E11")), " ") & Format(Date, "yyyymmdd") & Range("g10") & Range("a5") 'batch header rt-2,Btch ID-30,Btch Dt, post to dt,journal name
'9 For MyRow = FirstRow To LastRow 'loop through each row of the table
'10 MyStr = ""
'11 MyStr = "10" & Cells(MyRow, 1).Value & String(25 - Len(Cells(MyRow, 1).Value), " ") 'Rec type + GL account number
'12 MyStr = MyStr & String(12 - Len(Cells(MyRow, 5).Value numberformat=###.00), " ") & Cells(MyRow, 5).Value * 100 'Debit amount
'13 MyStr = MyStr & String(12 - Len(Cells(MyRow, 6).Value), " ") & Cells(MyRow, 6).Value * 100 'Credit amount
'14 Print #2, MyStr
'15 Next
'16 Print #2, "99" ' MyTrailer
'17 Close #2
'18 Sheets("JE Upload").Range("F2").ClearContents ' note that this row expects the worksheet to be named JE Upload
'19 Sheets("JE Upload").Hyperlinks.Add Range("F2"), PageName
'20 End Sub<o


<o

