I have modified my original UDF so that you can specify how many characters to return. In order to do that, I had to add an additional argument (the number of characters to return), and I changed the name of the function to Chars (note the "s" on the end to distinguish it from Excel's CHAR function), plus I also changed it to use " Batch " instead of " z ", so you would now have to write your formula like this....
For 4 characters: =Chars(A2,4)
For 5 characters: =Chars(A2,5)
and so on. Here is the revised macro to use...
Function Chars(S As String, Num As Long) As String
Dim X As Long, Txt() As String
Txt = Split(Split(" " & S, " Batch ", , vbTextCompare)(1))
For X = 0 To UBound(Txt)
If Txt(X) Like Application.Rept("[A-Za-z0-9]", Num) Then
Chars = Txt(X)
Okay, I somehow missed Message #22 (the "z" has no spaces around it, plus it is not the word "Batch")... so now I am confused at what the OP actually wants. I am going to sleep now, so hopefully the OP's needs will be clarified by the time I get up.
My understanding is to read "Batch" in place of "z" in the sample. The point I was making to oldbrewer though was that the expected result is not the first 4 characters after the first space after the "z/Batch".
I was just trying to provide a real life example using batch instead of z. What I'm trying to do with this formula is to get a 4 digit check number that comes after batch. I think the formulas and macros from Marcelo and Rick give this to me.