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:
1060
1132
1.2523.32

<colgroup><col width="64" span="2" style="width:48pt"> </colgroup><tbody>
</tbody>
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
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,221,444
Messages
6,159,914
Members
451,603
Latest member
SWahl

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