Extract integers or float from particular line of text file to excel

narayanan28997

New Member
Joined
May 14, 2019
Messages
2
Could you please help me to code the following:
I need to pick only the integers/float from a particular line of the text file (say line 2 qnd 3) and store it in an excel with each integer in a separate cell in sequence?

text file:
[Page1]
MotorP_AvgTemp= 10, 11, 1.25
MotorP_PackVoltage= 60, 32, 23.32

excel output:
[TABLE="width: 128"]
<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>[TR]
[TD="width: 64, align: right"]10[/TD]
[TD="width: 64, align: right"]60[/TD]
[/TR]
[TR]
[TD="align: right"]11[/TD]
[TD="align: right"]32[/TD]
[/TR]
[TR]
[TD="align: right"]1.25[/TD]
[TD="align: right"]23.32[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
Assuming the data starts at A1

Code:
Option Explicit
Dim LastRowNo As Long
Dim RowCount As Long
Dim RowWrite As Long
Dim ColWrite As Long
Dim ValStr As String
Dim TmpStr As String


Sub SortIntegers()


LastRowNo = ActiveSheet.Range("A65536").End(xlUp).Row 'set range to 1048576 if your sheet can go that high


For RowCount = 1 To LastRowNo
    ColWrite = 2 'start in column B
    If ActiveSheet.Range("A" & RowCount).Value <> "[Page1]" Then
        TmpStr = ActiveSheet.Range("A" & RowCount).Value
        ValStr = Mid(TmpStr, InStr(1, TmpStr, "=") + 1, Len(TmpStr))
        RowWrite = 5 ' start at row 5
        Do While InStr(1, ValStr, ",") > 1
            TmpStr = Left(ValStr, InStr(1, ValStr, ",") - 1)
            ActiveSheet.Cells(RowWrite, RowCount).Value = TmpStr
            ValStr = Mid(ValStr, InStr(1, ValStr, ",") + 1, Len(ValStr))
            RowWrite = RowWrite + 1
        Loop
        ActiveSheet.Cells(RowWrite, RowCount).Value = ValStr
        ColWrite = ColWrite + 1
    End If
Next RowCount
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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