title: Error 13 : Type Mismatch Error // Error not highlighted
body: <p>I am currently getting an <code>&quot;Error 13: Type Mismatch &quot;</code> Error for the following code and I can't seem to find where the problem is coming from</p>
  <p>I have added the Option Explicit code to try and assist but it still doesn't highlight anything when the program is executed.</p>
  <pre><code>Option Explicit
  Public mainWB As Workbook
  Public mainWS As Worksheet
  Public newWS As Worksheet
  
  Sub Main()
  
  'Creating New Variables
  Dim TranstactDate As String, AmountExcl As Single
  Dim mainR As Long, mainC As Long, newR As Long, newC As Long
  Dim randNumber As Long
  Dim accHolder As String
  
  newR = 2 'start of writing Row
  
  Set mainWB = Workbooks(&quot;arrears-formatter.xlsx&quot;) 'Setting mainWB
  Set mainWS = mainWB.Worksheets(&quot;arrears-formatter&quot;) ' set mainWS to the working Worksheet
  
  mainWB.Activate 'Shows that were working in the mainWB workbook
  randNumber = Int((99999 - 10000 + 1) * Rnd + 10000)
  
  TranstactDate = mainWS.Cells(1, 2)
  
  For mainR = 9 To 1000
      If mainWS.Cells(mainR, 1) = &quot;&quot; Then GoTo exitthis:
      
      accHolder = Left(mainWS.Cells(mainR, 1), 3)
      
      AmountExcl = mainWS.Cells(mainR, 3)
      
      While Left(mainWS.Cells(mainR, 1), 3) = accHolder
          Set newWS = mainWB.Worksheets(accHolder + &quot;-&quot; + randNumber)
          
          newWS.Range(&quot;A2:A1000&quot;).NumberFormat = &quot;@&quot;
          'Determining new sheet values
          newWS.Cells(newR, 1) = TranstactDate
          newWS.Cells(newR, 1).NumberFormat = &quot;dd/mm/yyy&quot;
          newWS.Cells(newR, 2) = mainWS.Cells(mainR, 1)
          newWS.Cells(newR, 3) = &quot;AR&quot;
          newWS.Cells(newR, 4) = &quot;Interest&quot;
          newWS.Cells(newR, 5) = &quot;0&quot;
          newWS.Cells(newR, 6) = &quot;7&quot;
          newWS.Cells(newR, 7) = &quot;Interest&quot;
          newWS.Cells(newR, 8) = &quot;&quot;
          newWS.Cells(newR, 9) = AmountExcl
          newWS.Cells(newR, 10) = &quot;&quot;
          newWS.Cells(newR, 11) = &quot;&quot;
          newWS.Cells(newR, 12) = &quot;0&quot;
          newWS.Cells(newR, 13) = AmountExcl
          newWS.Cells(newR, 14) = &quot;1&quot;
          newWS.Cells(newR, 15) = AmountExcl
          newWS.Cells(newR, 16) = AmountExcl
          newWS.Cells(newR, 17) = &quot;0&quot;
          newWS.Cells(newR, 18) = &quot;0&quot;
          newWS.Cells(newR, 19) = &quot;&quot;
          newWS.Cells(newR, 20) = &quot;0&quot;
          newWS.Cells(newR, 21) = &quot;0&quot;
          newWS.Cells(newR, 22) = &quot;0&quot;
          newWS.Cells(newR, 23) = &quot;&quot;
          newWS.Cells(newR, 24) = &quot;&quot;
          newWS.Cells(newR, 25) = &quot;0&quot;
          newWS.Cells(newR, 26) = &quot;0&quot;
          newWS.Cells(newR, 27) = &quot;&quot;
          newWS.Cells(newR, 28) = &quot;0&quot;
          newWS.Cells(newR, 29) = &quot;0&quot;
          newWS.Cells(newR, 30) = &quot;0&quot;
          newWS.Cells(newR, 31) = &quot;2750&gt;050&quot;
          newWS.Cells(newR, 32) = &quot;0&quot;
          newWS.Cells(newR, 33) = &quot;0&quot;
          
          newR = newR + 1
      Wend
  exitthis:
  Next mainR
  
      newWS.Cells(1, 1) = &quot;Trans Date&quot;
      newWS.Cells(1, 2) = &quot;Account&quot;
      newWS.Cells(1, 3) = &quot;Module&quot;
      newWS.Cells(1, 4) = &quot;Trans Code&quot;
      newWS.Cells(1, 5) = &quot;Post Date&quot;
      newWS.Cells(1, 6) = &quot;Reference&quot;
      newWS.Cells(1, 7) = &quot;Description&quot;
      newWS.Cells(1, 8) = &quot;Order Number&quot;
      newWS.Cells(1, 9) = &quot;Amount Excl&quot;
      newWS.Cells(1, 10) = &quot;Tax Type&quot;
      newWS.Cells(1, 11) = &quot;Tax Account&quot;
      newWS.Cells(1, 12) = &quot;Is Debit&quot;
      newWS.Cells(1, 13) = &quot;Amount Incl&quot;
      newWS.Cells(1, 14) = &quot;Exchange Rate&quot;
      newWS.Cells(1, 15) = &quot;Foreign Amount Excl&quot;
      newWS.Cells(1, 16) = &quot;Foreign Amount Incl&quot;
      newWS.Cells(1, 17) = &quot;Discount Percent&quot;
      newWS.Cells(1, 18) = &quot;Discount Amount Excl&quot;
      newWS.Cells(1, 19) = &quot;Discount Tax Type&quot;
      newWS.Cells(1, 20) = &quot;Discount Amount Incl&quot;
      newWS.Cells(1, 21) = &quot;Foreign Discount Amount Excl&quot;
      newWS.Cells(1, 22) = &quot;Foreign Discount Amount Incl&quot;
      newWS.Cells(1, 23) = &quot;Project Code&quot;
      newWS.Cells(1, 24) = &quot;Rep Code&quot;
      newWS.Cells(1, 25) = &quot;Split Group&quot;
      newWS.Cells(1, 26) = &quot;Split GL Account&quot;
      newWS.Cells(1, 27) = &quot;Split Description&quot;
      newWS.Cells(1, 28) = &quot;Split Amount&quot;
      newWS.Cells(1, 29) = &quot;Foreign Split Amount&quot;
      newWS.Cells(1, 30) = &quot;Split Project Code&quot;
      newWS.Cells(1, 31) = &quot;GL Contra Code&quot;
      newWS.Cells(1, 32) = &quot;Split Tax Type&quot;
      newWS.Cells(1, 33) = &quot;Split Tax Account&quot;
      
     
      
  With newWS.Sort
       .SortFields.Add Key:=Range(&quot;C2&quot;), Order:=xlAscending
       .SetRange Range(&quot;A2:G1000&quot;)
       .Header = xlNo
       .Apply
  End With
  
  
  End Sub
  </code></pre>
  <p>Please kindly assist if you can see where this error comes from , its just used to re-format an excel sheet</p>