Find positions in a string

lins0340

New Member
Joined
Jul 18, 2011
Messages
1
I would like to retrieve the exact positions of point in a string. Example:

"12.3.23.5.10." The result should be:

point 1 : 3
point 2 : 5
point 3 : 8
point 4 : 10
point 5 : 13

Can anybody tell me how to do that?
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
With
A1: containing your sample value: 12.3.23.5.10.

and Col_D cells containing the instance to locate
D1: 1
D2: 2
D3: 3
D4: 4
D5: 5

This regular formula returns the position of the decimal point referenced in Col_D
Code:
E1: =FIND("|",SUBSTITUTE($A$1,".","|",D1))
Copy that formula down through E5 to see the other positions.

These are the E1:E5 results:
3
5
8
10
13

Is that something you can work with?
 
Upvote 0
With VBA:
Code:
Sub GetPointPositions()
    Dim PointData As String
    Dim PointCount As Integer
    Dim PointPositions As String
    Dim LastPoint As Integer
    Dim ThisPoint As Integer
    Dim i As Integer
    
    PointData = Range("A1")
    PointCount = Len(PointData) - Len(Replace(PointData, ".", ""))
    For i = 1 To PointCount
        ThisPoint = InStr(LastPoint + 1, PointData, ".")
        PointPositions = PointPositions & ThisPoint & ","
        LastPoint = ThisPoint
    Next i
    PointPositions = Left(PointPositions, Len(PointPositions) - 1)
    
    'There are various ways to extract individual positions
    Range("A2:A6").ClearContents
    For i = 1 To PointCount
        Range("A" & i + 2) = "point " & i & " : " & Split(PointPositions, ",")(i - 1)
    Next i
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,516
Messages
6,179,231
Members
452,898
Latest member
Capolavoro009

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