title: Run Time error : 5 invalid procedure call or argument in VBA
body: <pre><code>Private Sub btnsubmit_Click()
  
  Dim Msg As String
  Dim pos1 As Integer
  Dim pos2 As Integer
  Dim Count As Integer
  Dim flag As Integer
  Dim telphno    
  
  Msg = TextBox1.Value
  pos1 = 1
  pos2 = 1
  
  flag = 0
  
  Do While pos1 &lt; Len(Msg)
  
      pos1 = InStr(pos1, Msg, "[")
      If flag = 0 Then
          pos2 = InStr(pos2, Msg, "]")
      End If
  
      If pos2 - pos1 &lt; 5 Then
          ActiveCell.Value = Mid(Msg, pos1 + 1, pos2 - pos1 - 1)        
          Count = 0
  
          'Loop through the entire string
          For i = pos2 To Len(Msg)
  
              'Check to see if the character is a numeric one
              If IsNumeric(Mid(Msg, i, 1)) Then
  
                  'Add it to the answer
                  telphno = telphno + Mid(Msg, i, 1)
                  Count = Count + 1                    
  
                  'Check to see if we have reached 10 digits
                  If Count = 10 Then Exit For                        
  
              Else
                  telphno = ""
                  Count = 0                
              End If
  
          Next i
  
          ActiveCell.Offset(0, 1).Value = telphno
          flag = 0
          ActiveCell.Offset(1, 0).Select
          pos1 = pos2 + 1
          pos2 = pos1
          telphno = ""        
      Else
          flag = 1
          pos1 = pos1 + 1            
    End If
  
  Loop
  
  End Sub
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/69Nov.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/69Nov.png" alt="I am getting error on using MID function highlighted in yellow."></a></p>
  
  <p>I am trying to fetch the characters between "[" and "]" in my string but MID function is giving me error. Please help me to fix this problem.</p>
  
  <p>After finding the Characters between "[" and "]" I am looking for nearest 10 digit number. I am taking the string through TextBox (User Input).
  And Printing the output on Excel Sheet.</p>
  
  <p>For ex- </p>
  
  <pre><code>[A22]1239163332bcfhds[B23]6453jhddf2784637281ajdnjda[C33]dksamkd1288776655
  </code></pre>
  
  <p>For the above string. It should give - </p>
  
  <pre><code>A22 1239163332  
  B23 2784637281
  C33 1288776655  
  </code></pre>
  
  <p>Input 2 -  </p>
  
  <p><code>@ﬁJaeasaﬁGpaaaaod [A1] # 42, 5532 23156 “63’ 8:355 dedmaa @656 663336, {33538365. sail &amp; as" 53666 wee—9008799499. @dﬁs.ée.maae06 [A2] S/O éegddad mweeﬁ @dﬁE aaseaeﬁ mwaossae We" ﬂees?) all 359% as" ﬁdee, wee—9886557596.
  $036903: WI 29365 amass @aoﬂae maﬁa] (me) sail was?“ asllmairid’, aha—9945173528. @6066 60333305 2:056. [A4] £06333 messes $6503.91:
  33:12:05 mews. 8.133133% a?" aiding as" mamas.
  aha-9886444737. [50%. memergﬁos, [A5] mew 89335365 mamas.
  mama. aan wage, as" eagdade, diam—9731742667. eaaiodﬁaas. [A6]
  ge Wagﬁegd mwaoﬁsae maﬁa) £3966.maﬁa).sail mg"), as" mairiﬁ, met—9986611558. @8396 30653236 [A7] ﬂeas $839395 ﬂeas# 4138/38, Sgéegd 33905:,623 ﬁnaSeag soomrf,ao.&amp;.&amp;.‘w’ea§ss,$3913.29. ﬁdeaas 6:312:36,anaemia.all dog as" macaw-36,mom—9448166197.mamas 8985305 [A8192 ageng mews sambaaadeﬁaeﬁéﬁeo.all adswsg, all warm,dam—9945363102.@69535 games [A9]amasssesame@06.ao.&amp;.dsaec56maisaﬁd.aall $33.19 as" mamrid’,wag—9844644272.as.demam] 33mmadésada.Gall 836%62, as" $3668,
  wee:—8.839%:ngge [imam meme $36033“ﬂaccid weave.mweaﬁd.all 623; as" maiarid,dam—9481161243.agodaé.8.ao.129330556 agaossae53%;.a?" &amp; as" 5365366,mez—990187114-1.8884232296@2353e65@55.@05.9:330:36 @9033“we ems aim-.1353,swag.all 666663, as" maladdwag—8123565686.gang-56$60506 masses ﬁaoﬁaemaﬁﬂeas mews,swag.all 8665383, as" mdwﬁd
  aha—9845781954.[A10][A11][A12][A13][A14]$63535 3:633:56 [A15]@663 aaaaaeﬁ SawadJaeawe: aa£eas€ mews,{3368366.sail 6.9% all 0369966,dam—9945707587eaoadﬁ mesmereaa’cﬁwsl6:36:38 agaoisaeﬁasﬁewéédaall 303:3, as" 03653613,dam-9900436152.$830335eiedaﬁ $885366 Qawaeeiapﬂsaecss,asasdne.aall wipe, as" 53566,Elma—9448218974.$69836 memergﬁos [A18]# 167,“&amp;oa5555”15’ 2:336, 63:: @55,deg-353255 9:355 acme-3%,massariﬁ.aall 3.3.333 as” nae-36386,WEE—9342495800.@%§ mewaergﬁcs [A19]# 794/8 oomﬁeo.modes mews,65366666.all 6333 as" mwwﬁ'ﬁ,dam—9945434802.$830535 Meme®$cs [A20]@30335 masses Mathewsmandaoddwsg.sail ﬁne]; as" 53538363,met-9980170633.@506 memergaos903361103: $358365 Saaawsae3536333.Ball 36335623, as" $368966,Wei-9972675782[A17] [A21]</code></p>
  
  <p>Expected Ouput - </p>
  
  <p>A1 9008799499<br>
  A2 9886557596<br>
  A4 9886444737<br>
  A5 9731742667<br>
  A6 9986611558<br>
  A7 9448166197<br>
  and so on till<br>
  A20 9980170633</p>