title: Excel VBA - Returning Positions of all Sub-Strings within a String from the Clipboard
body: <p>I'm trying to find all the positions of the unique keys (followed by two Tab keystrokes) in a string in taken from clipboard, positions with which I then hope to use to insert carriage returns, and then have everything put back into the clipboard again. </p>
  
  <p>First things first; getting the position part to work!</p>
  
  <p>Here is a shortened example of the string:</p>
  
  <pre><code>Initial Approval in First Market or Non-Submitted Closure       090052fb842ef82f        090052fb842f3659        090052fb842ef82e        
  </code></pre>
  
  <p>Here is the non-functional code I have put together so far from researching the problem:</p>
  
  <pre><code>Sub oldRecords()
  
  Dim clipboard As MSForms.DataObject
  Dim strContents As String
  
  Set clipboard = New MSForms.DataObject
  clipboard.GetFromClipboard
  strContents = clipboard.GetText
  
  Set objRegEx = CreateObject("vbscript.regexp")
  objRegEx.Pattern = "(090052fb)[0-9A-Za-z]{8}\t\t"
  objRegEx.Global = True
  objRegEx.IgnoreCase = True
  objRegEx.MultiLine = True
  
  Start = 1
  Do
    pos = InStr(Start, strContents, objRegEx.Execute(strContents), vbBinaryCompare)
    If pos &gt; 0 Then
      Start = pos + Len(objRegEx.Pattern)
      WScript.Echo pos
      WScript.Echo Mid(strContents, pos, Len(objRegEx.Pattern))
    End If
  Loop While pos &gt; 0
  
  End Sub
  </code></pre>
  
  <p>Right now I am getting a Run-time error '450': Wrong number of arguments or invalid property assignment, and I believe the culprit is:</p>
  
  <pre><code>objRegEx.Execute(strContents)
  </code></pre>
  
  <p>I'm not sure where to go from here, so any help would be fantastic! :)</p>
  
  <p>Edit 1:
  Firstly thank you for the interest in my issue!</p>
  
  <p>BrackNicku has provided a simple solution for a problem I evidently thought more complex than it needed to be! Here is the code I finally went with, adding in a few extra bits that I needed on top of the core issue:</p>
  
  <pre><code>Sub oldRecords2()
      Dim clipboard As MSForms.DataObject
      Dim strContents As String
      Dim start As Long, pos As Long
  
      Set clipboard = New MSForms.DataObject
      clipboard.GetFromClipboard
      strContents = clipboard.GetText
      Dim objRegEx
      Set objRegEx = CreateObject("vbscript.regexp")
      objRegEx.Pattern = "(090052fb[0-9A-Za-z]{8})\t\t"
      objRegEx.Global = True
      objRegEx.IgnoreCase = True
      objRegEx.MultiLine = True
  
      X1 = 10                                                                     ' Line Feed Character
      X2 = 13                                                                     ' Carriage Return Character
      X3 = "Archive Custodain Group"
      X4 = "Archive Custodain Group" &amp; Chr(X2)
      '======================================================================================================
  
      strContents = Replace(strContents, Chr(X1), "")                             ' REMOVES LINE FEEDS
      strContents = Replace(strContents, X3, X4)                                  ' ADDS CR AFTER TITLE ROW
  
      strContents = objRegEx.Replace(strContents, "$1" &amp; vbNewLine)
      '======================================================================================================
  
      clipboard.SetText strContents                                               'PUT BACK INTO CLIPBOARD
      clipboard.PutInClipboard
  End Sub
  </code></pre>