title: VBA How do i split an integer into separate parts
body: <p>I'm working in VBA within Excel.
  I need to split the integer into two parts, specifically the first two digits and the last two digits.
  The numbers have a maximum of four digits and at least one. (I've already sorted out the blank values) eg. </p>
  
  <p>7 should become 0 and 7,</p>
  
  <p>23 should become 0 and 23,</p>
  
  <p>642 should become 6 and 42,</p>
  
  <p>1621 should become 16 and 21.</p>
  
  <p>This is the code I have so far</p>
  
  <pre><code>Function Bloog(value1 As Integer)
  
  Dim value1Hours, value1Mins As Integer
  
  Select Case Len(value1) 'gives a number depending on the length of the value1
      Case 1, 2 ' e.g., 2 = 0, 2 or 16 = 0, 16
          value1Hours = 0
          value1Mins = value1
      Case 3 ' e.g., 735 = 7, 35
          value1Hours = Left(value1, 1) ' 7
          value1Mins = Right(value1, 2) ' 35
      Case 4 ' e.g., 1234 = 12, 34
          value1Hours = Left(value1, 2) ' 12
          value1Mins = Right(value1, 2) ' 34
  End Select
  </code></pre>
  
  <p>However when go to get the values i find that they have not been split up into the separate parts as the Left() and Right() function would have me believe.
  Len() doesn't appear to be working either, when it was given the value 723 it returned a length of 2.</p>
  
  <p>Any tips would be appreciated. </p>
  
  <p>=======================================</p>
  
  <p>After a suggestion I've cast the values as strings then done the case statement and converted them back afterwards. (because I need them for some calculations)</p>
  
  <pre><code>Private Function Bloog(value1 As Integer) As Integer
  
  Dim strValue1 As String
  Dim strValue1Hours, strValue1Mins As String
  Dim value1Hours, value1Mins As Integer
  
  'converts the values into strings for the Left() and Right() functions
  strValue1 = CStr(value1)
  
  Select Case Len(value1) 'gives a number depending on the length of the value1
      Case 1, 2 ' e.g., 2 = 0, 2 or 16 = 0, 16
          strValue1Hours = 0
          strValue1Mins = value1
      Case 3 ' e.g., 735 = 7, 35
          strValue1Hours = Left(value1, 1) ' 7
          strValue1Mins = Right(value1, 2) ' 35
      Case 4 ' e.g., 1234 = 12, 34
          strValue1Hours = Left(value1, 2) ' 12
          strValue1Mins = Right(value1, 2) ' 34
  End Select
  
  value1Hours = CInt(strValue1Hours)
  value1Mins = CInt(strValue1Mins)
  </code></pre>
  
  <p>Len() still believes that the length of the string is 2 and so case 2 statement was triggered, despite this the the strValue1Mins and the value1Mins still equals 832.</p>
  
  <p>=======================</p>
  
  <p>Len() was testing for Value1 not strValue1, everything works fine after that.</p>