Currently we have a small bit of code that gets the value of a cell and returns 4 digits of it.
For example L1234 would be 1234, D1234 would be 1234
However now we have values that are 5 digits L12345 for example and they are just being returned as the last 2 digits. e.g. L12345 is being returned as 45
What i want is to modify the code to allow for both 4 and 5 digit variants.
Current Code:
  If GetElm(Range("F" & i).value, 3) = "8260" Then
    CodeD = GetElm(Range("F" & i).value, 4)
  End If
  col9 = Right(CodeD, 4)
This returns:
Input   Output
L1234   1234
L12345  45
What I have tried:
  If GetElm(Range("F" & i).value, 3) = "8260" Then
    CodeD = GetElm(Range("F" & i).value, 4)
  ElseIf GetElm(Range("F" & i).value, 3) = "8260" Then
    CodeD = GetElm(Range("F" & i).value, 5)
  End If
  col9 = Right(CodeD, 5)
This Returns:
Input   Output
L1234   L1234
L12345  12345
This returns the 5 digit ones correctly, but the 4 digit ones are being returned with the letter.
EDIT:
GetElm Definition:
Function GetElm(value As String, elmno As Integer)
If elmno = 1 Then
  GetElm = Left(value, 1)
ElseIf elmno = 2 Then
  GetElm = Mid(value, 3, 3)
ElseIf elmno = 3 Then
  GetElm = Mid(value, 7, 4)
ElseIf elmno = 4 Then
  GetElm = Mid(value, 12, 8)
End If
End Function
 
     
    