Hi,
I have written a macro for converting a txt file to excel file by giving file name and position as input from user
the position is givenn as (1:5 6:7 etc..which means from 1 st position to 5 letters goes to 1 st colm of excel and from 6 th posn to 7 letters to 2 nd cell and so on)
Dim text
Dim fn
Dim delim
Public Sub CommandButton1_Click()
fn = Application.GetOpenFilename
If fn = False Then
MsgBox "Nothing Chosen"
Exit Sub
End If
End Sub
Public Sub TextBox2_Change()
text = UserForm1.TextBox2.text
End Sub
Private Sub CommandButton2_Click()
Dim stext As Variant
Dim arrays As Variant
Dim fso As New FileSystemObject
Dim txtStream
Set txtStream = fso.OpenTextFile(fn)
line = txtStream.ReadLine
Dim row1, i As Integer
Dim l, m As Integer
Dim n As String
Dim texts(2) As Integer
row1 = 1
i = 1
Do While Not txtStream.AtEndOfStream
arrays = split(text, " ")
For k = LBound(arrays) To UBound(arrays)
stext = split(arrays(k), ":")
For i = 0 To 1
texts(i) = CInt(stext(i))
Next
l = texts(0)
m = texts(1)
Cells(row1, i).Value = Mid(line, l, m)
i = i + 1
Next
row1 = row1 + 1
Loop
txtStream.Close
End Sub
---------------------------------------
but is giving errors in the "texts(i) = CInt(stext(i)" line as subscript out of range
pls help me on this
Bookmarks