Get 3rd occurrence of string

dsusercs

New Member
Joined
Mar 27, 2013
Messages
9
Hi,

I have a text file from which I'm locating a string as 'Name "$' and reading third line from then which is expected to be 'Default "$'. Double quote is a part of the string that I'm searching for. Please note that both the strings occur n number of times and I have to read them all and write to a worksheet with all 'Name "$' in col 1 and 'Default "$' in col 2. For every occurrence of 'Name "$', I have to read the 3rd line. I have the code below,

fn = "testfile.txt"
delim = vbTab
temp = CreateObject("Scripting.FileSystemObject").OpenTextFile(fn).ReadAll
x = Split(temp, vbCrLf)
ReDim a(1 To UBound(x) + 1, 1 To 100)
For i = 0 To UBound(x)
If InStr(1, x(i), "INSTALLATION", 1) > 0 Then
For ii = 0 To 2
n = n + 1: y = Split(x(i + ii), delim)
For iii = 0 To UBound(y)
a(n, iii + 1) = y(iii)
Next
Next
End If
If n > 0 Then
Sheets(1).Cells(1,1).Resize(n, 100).Value = a

Any help here?
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.

Forum statistics

Threads
1,203,462
Messages
6,055,565
Members
444,799
Latest member
CraigCrowhurst

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