VBA Script to extract two sets of numbers between text in cell

johnbrownbaby

New Member
Joined
Dec 9, 2015
Messages
38
Hello,

Thanks to the elegant solution to the first question posted here, I was able to get a formula based solution. I am finding that if the data is given like this:

1637176548920.png


I am having a problem keeping up with the formula based approach. How can I do this from VB script viewpoint to collect the data from column A where all the "eFine" and "eFood" numbers are placed in separate columns found in K and L respectively?

I posted a preliminary question on OzGrid found here but I do not know how to delete that question to make this updated question priority.

test1.xlsx
ABCDEFGHIJKLMNO
1Test 1Amp
2240485212827
3240489212855
4240486012914
5240458913015
6
7Pack: AMPLITUDE_ACCESS
8eFine: 2404852 eFood: 12827
9
10
11
12
13
14Pack: AMPLITUDE_ACCESS
15eFine: 2404892 eFood: 12855
16
17
18
19
20
21Pack: AMPLITUDE_ACCESS
22eFine: 2404860 eFood: 12914
23
24
25
26
27
28Pack: AMPLITUDE_ACCESS
29eFine: 2404589 eFood: 12015
30
31***
32*** DISCONNECT
33*** time 14:38:02
34***
35
36
37[INFO] INFO: DISCONNECTED
38
39
40Pack: AMPLITUDE_ACCESS
41eFine: 2404892 eFood: 12855
42
43
44
45
46
47Pack: AMPLITUDE_ACCESS
48eFine: 2404860 eFood: 12914
49
50
51
52
53
54Pack: AMPLITUDE_ACCESS
55eFine: 2404589 eFood: 12015
56
57***
58*** DISCONNECT
59*** time 14:38:02
60***
61
62
63[INFO] INFO: DISCONNECTED
Sheet1


Thanks for your help and time!
 
In your example you only have 4 results, I assumed that you only wanted the unique values. But if you want all, on all sheets, try the following. The results will be on the first sheet.

VBA Code:
Sub extract_two_sets_of_numbers2()
  Dim r As Range, f As Range
  Dim cell As String
  Dim arr As Variant
  Dim sh As Worksheet
 
  For Each sh In Sheets
    Set r = sh.Range("A1", sh.Range("A" & Rows.Count).End(3))
    Set f = r.Find("eFine", , xlValues, xlPart, , , False)
    If Not f Is Nothing Then
      cell = f.Address
      Do
        arr = Split(f.Value, " ")
        Sheets(1).Range("K" & Rows.Count).End(3)(2).Resize(, 2).Value = Array(arr(1), arr(3))
        Set f = r.FindNext(f)
      Loop While Not f Is Nothing And f.Address <> cell
    End If
  Next
End Sub
THANK YOU!
 
Upvote 0

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,214,907
Messages
6,122,183
Members
449,071
Latest member
cdnMech

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