formatting-a-text-file-and-exporting-a-text-file

kakhils

New Member
Joined
Aug 20, 2015
Messages
19
I have a code which separates the range into numbers.
Its is working fine. but i want to add a fixed data end of every number.
Below is the number. 102201906000-102201911999-23451

The code
Sub Macro1()



On Error Resume Next


StartTime = Now()
Dim objFSO, objFolder, objFile, strFileName, strExtension
'Dim a(1048500, 6)
Dim arr(3000)
Dim fs, a, f, mis
Dim maf As Double

Set fs = CreateObject("Scripting.FileSystemObject")
stroutpath = Range("C5").Value


'a.WriteLine ("Mobile_No,Total_Current_Charge,Current_charges_with_Tax,Monthly_Access_Fee,Outgoing_National_Calls,Outgoing_International_Calls,MOC_-_SMS_Messages,Roaming_SMS,Roaming_Incoming,Roaming_OGC,GPRS_Vol_Home,Roam_GPRS_Usage,Jinny_RBT,Call_Fwd_Calls,Excise_Duty,VAT")
If Sheet1.Range("C4").Value = "" Then
MsgBox "Enter File Path"
Exit Sub
End If
strdirpath = Range("C4").Value


Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFSO.GetFolder(strdirpath)

For Each objFile In objFolder.Files

If InStr(1, objFile.Name, ".txt") > 0 Then
strFileName = UCase(objFile.Name)
Else: strFileName = ""
GoTo a
End If

ReadFile = strdirpath & "\" & strFileName
Const ForReading = 1, ForWriting = 2, ForAppending = 3


Set a = fs.CreateTextFile(stroutpath & "\" & strFileName, True)
''Set b = fs.CreateTextFile(stroutpath & "\" & strFileName, True)


Set fs = CreateObject("Scripting.FileSystemObject")
Set fin = fs.OpenTextFile(ReadFile, ForReading, TristateFalse)




'ReadNextLine = False
Do While fin.AtEndOfStream <> True
readata = fin.readline
writedata = IIf(InStr(1, readata, "M,") > 1, Mid(readata, 1, InStr(1, readata, ",") - 1), "")


If Len(writedata) > 11 Then
a.writeline (writedata)
End If




Loop


a:
Next
tt = Format(Now() - StartTime, "HH:MM:SS")
MsgBox "Complete Time taken " & tt
End Sub


Above code only separates Range into numbers like.102201906000
102201906001 102201906002 102201906003 till102201911999.

But i want a fixed digit on every number
102201906000 23451
102201906001 23451
102201906002 23451
till
102201911999 23451.
These should be done in a new text file as export.
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
I havent followed all what your code does but somewhere something like this

Set a = fs.CreateTextFile(stroutpath & "\" & strFileName & " 23451", True)
 
Upvote 0
Dear Thanks for your reply.. This is Fixed for one data .. for other data.. there are other fixed value.
For e.g.


6004151093000-6004151141648-23456
6004151141650-6004151142999-92736

Please help !!
 
Upvote 0
you can use rules to drive the variables, I see no indication as to what event drives what rule
 
Upvote 0

Forum statistics

Threads
1,215,457
Messages
6,124,941
Members
449,198
Latest member
MhammadishaqKhan

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top