how to take data from next line of a text file and put in excel format

anupamduttabesu

New Member
Joined
Mar 24, 2013
Messages
5
Hi
I have multiple text file where under ZEBI command datas are in the format...the datas under the command ZEBI ends with "COMMAND EXECUTED ".


< ZEBI;
LOADING PROGRAM VERSION 21.15-0
EXECUTION STARTED


BSC3i BSC1000 2012-04-10 11:23:49
MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800
FREQUENCIES:
874 875 876 877 878 879 880 881
ATTACHED AS MOBILE ALLOCATION FREQUENCY LIST TO BTS:
549 KOL51731 619 KOL51732 620 KOL51733
1124 KOL49141
MOBILE ALLOCATION FREQUENCY LIST - 2 BAND ... 1800
FREQUENCIES:
802 803 804 805
COMMAND EXECUTED

Now i need the data in excel format as below.....


MOBILE ALLOCATION FREQUENCY LIST</SPAN>BAND</SPAN>FREQUENCIES</SPAN>
1</SPAN>1800 </SPAN>874 875 876 877 878 879 880 881 </SPAN>
2</SPAN>1800 </SPAN> 802 803 804 805 </SPAN>

<TBODY>
</TBODY><COLGROUP><COL><COL><COL></COLGROUP>


Here From the text line
"MOBILE ALLOCATION FREQUENCY LIST - 1 BAND ... 1800"
We take data 1 and 1800 and put in the excel under the header MOBILE ALLOCATION FREQUENCY LIST AND BAND.
And fron the two lines
"FREQUENCIES:
874 875 876 877 878 879 880 881"
we take data "874 875 876 877 878 879 880 881" under the header FREQUENCY.

Please help how to write the macro for that.
I have made a code to write the macro,but i am not abale to take the data from the next line of "FREQUENCY".
Here is the code..
Dim sFileName As Variant
Dim iFileNum As Integer
Dim sBuf As String

Dim bolRecordAdding As Boolean
Dim aryData As Variant
Dim aryOutput As Variant

ReDim aryData(1 To 4, 0 To 0)

sFileName = Application.GetOpenFilename(",*.txt", , , , True)

For a = LBound(sFileName) To UBound(sFileName)
iFileNum = FreeFile()

Open sFileName(a) For Input As iFileNum
Do While Not EOF(iFileNum)
Line Input #iFileNum, sBuf
If Not InStr(sBuf, "ZEBI") = 0 Then
Do While Not sBuf = "FREQUENCIES: "
Line Input #iFileNum, sBuf
If sBuf Like "*BSC*" Then
If Not InStr(1, sBuf, " ") = 0 Then
abcd = Trim(Mid(sBuf, InStr(1, sBuf, " ") + 1, (InStr(12, sBuf, " ")) - (InStr(1, sBuf, " "))))
End If
End If
Loop
Do While Not sBuf = "COMMAND EXECUTED"

Line Input #iFileNum, sBuf

If sBuf Like "MOBILE ALLOCATION FREQUENCY LIST*" Then
If Not InStr(1, sBuf, "-") = 0 Then
ReDim Preserve aryData(1 To 4, 1 To UBound(aryData, 2) + 1)
aryData(1, UBound(aryData, 2)) = abcd
aryData(2, UBound(aryData, 2)) = Trim(Mid(sBuf, 37, 10))
aryData(3, UBound(aryData, 2)) = Trim(Mid(sBuf, 55, 10))
bolRecordAdding = True
End If

ElseIf sBuf Like "FREQUENCIES:*" Then
If Not InStr(1, sBuf, ":") = 0 _
And bolRecordAdding Then

aryData(4, UBound(aryData, 2)) = here what to write to take data from next line of frequency
bolRecordAdding = False
End If


End If

Loop
End If
Loop
Close iFileNum
Next a
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

Forum statistics

Threads
1,215,493
Messages
6,125,131
Members
449,206
Latest member
burgsrus

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