title: Excel User defined function - Field matches specific criteria
body: <p>New to vba - I am essentially try to make this very long if statement into a user defined function. The function would check if the field is the correct format of 2 letters, 2 numbers, an underscore, 1 letter, 2 numbers. </p>
  
  <pre><code>=IF(AND(AND(CODE(MID(A2,1,1))&gt;64,CODE(MID(A2,1,1))&lt;91),AND(CODE(MID(A2,2,1))&gt;64,CODE(MID(A2,2,1))&lt;91),AND(CODE(MID(A2,3,1))&gt;47,CODE(MID(A2,3,1))&lt;57),AND(CODE(MID(A2,4,1))&gt;47,CODE(MID(A2,4,1))&lt;57),CODE(MID(A2,5,1))=95,AND(CODE(MID(A2,6,1))&gt;64,CODE(MID(A2,6,1))&lt;91),AND(CODE(MID(A2,7,1))&gt;47,CODE(MID(A2,7,1))&lt;57),AND(CODE(MID(A2,8,1))&gt;47,CODE(MID(A2,8,1))&lt;57),"Good","Bad Syntax")
  </code></pre>
  
  <p>Example of A2 would be AA01_A05</p>
  
  <p>Code below - winged it in the end. Any help would be appreciated. </p>
  
  <pre><code>Function bincheck(strValue As String) As Boolean
  
  Dim AislePos As Integer, Rackno As Integer, Udr As Integer, ShelfPos As     Integer, BinNo As Integer
  Dim TrueAisle As Boolean, TrueRack As Boolean, TrueUdr As Boolean, TrueShelf As Boolean, TrueBin As Boolean
  
  For AislePos = 1 To 2
      Select Case Asc(Mid(strValue, AislePos, 1))
          Case 65 To 90
              TrueAisle = True
          Case Else
              TrueAisle = False
              Exit For
      End Select
  Next
  For Rackno = 3 To 4
      Select Case Asc(Mid(strValue, Rackno, 1))
          Case 48 To 56
              TrueRack = True
          Case Else
              TrueRack = False
              Exit For
      End Select
  Next
   For Udr = 5 To 5
      Select Case Asc(Mid(strValue, Udr, 1))
          Case Is = 95
              TrueUdr = True
          Case Else
              TrueUdr = False
              Exit For
      End Select
  Next
  For ShelfPos = 6 To 6
      Select Case Asc(Mid(strValue, ShelfPos, 1))
          Case 65 To 90
              TrueShelf = True
          Case Else
              TrueShelf = False
              Exit For
      End Select
  Next
   For BinNo = 7 To 8
      Select Case Asc(Mid(strValue, BinNo, 1))
          Case 48 To 56
              TrueBin = True
          Case Else
              TrueBin = False
              Exit For
      End Select
  Next
  Select Case bincheck
       Case TrueRack = True And TrueAisle = True And TrueUdr = True And TrueShelf = True And TrueBin = True
  bincheck = "Good"
      Case Else
  bincheck = "Bad"
  End Select
  End Function
  </code></pre>