Excel VBA extract specific text from cell

  • I have a cell with a very long string...
    (this is only the last part of it)

    EVO ITEMS (item folders/!CB Items/CBend0.bmp

    and I need to extract JUST the "CBend0" from it.
    Since the string is a filepath, I basically just need everything AFTER the last "/" and BEFORE the ".bmp"
    I can do it on the sheet itself using formulas, but I can't seem to be able to do it in VBA.
    Can anyone please help me?

  • This is coming from another beginner so take with grain of salt.

  • Thanks, but that won't work, as the .bmp filename may not always be the same length.
    So specifying the value of "10" won't always yield the desired result.

  • Maybe try something like:

    This assumes of course that the filename you are trying to extract before the ".bmp" extension does not contain any other full stops eg, CBend.0.bmp would only return the CBend value.

  • Hello,

    Attached is your test file with your customized UDF

    Function tomkat(sInput As String) As String
      Dim sArray() As String
      sArray = Split(sInput, "/")
      tomkat = Replace(sArray(UBound(Split(sInput, "/"))), ".bmp", "")
    End Function

    Hope this will help

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!