COL-A COL-B
00XA10010253 5
00XXXA10012267 1
00XA20045682 2
00XXXA23564457 4
00XAA1000253 1
00XAA200000 3
00XXA106402A01 5
I WANT IF COL-A = X , SUM COL-B
XX , SUM COL-B
XXX , SUM COL-B
PLEASE NOTE, I WANT AFTER THER LETTERS -BETWEEN FIRST 2DIGIT NUMBER(00) AND
EXCEPT -A
EXAMPLE IF 00XXXA200202A01 MEANS - I WANT" XXX "
AWAITNG YOUR HELP PLESE
-PER ANISH
It is not entirely clear to me what your requirements are.
If you only need to count the X's in a string, and if they only occur in one
place in the string, then Gary's students solution will work just fine.
However, if X's can also occur elsewhere in the string, it will fail.
What I see from your description is that you want to count the first instance
of X's that are preceded by two digits and followed by an A.
I would use a UDF, utilizing regular expressions, to do that.
This UDF will return TRUE or FALSE depending on if there is a pattern match.
This way you can vary the pattern to suit.
To enter the UDF, <alt-F11> opens the VBEditor. Ensure your project is
highlighted in the Project Explorer window, then Insert/Module and paste the
code below into the window that opens.
To use the UDF, enter a formula of the type:
=ReComp(cell_ref,pattern) into some cell and fill down as required.
One or more of the following patterns, or a variation may be useful:
Two digits followed by a single "X" followed by an "A"
"\d\dXA"
Two digits followed by two "X"'s followed by an "A"
"\d\dXXS"
Two digits followed by one capital letter that is not "A", then followed by an
A:
"\d\d[B-Z]A"
Two digits followed by two capital letters that are not "A", then followed by
an A:
"\d\d[B-Z]{2}A"
Two digits followed by two capital letters that are not "A", then followed by
an A:
"\d\d[B-Z]{3}A"
If the above patterns will only occur at the beginning of a line, then prepend
a "^" to the patterns. eg:
"^\d\dXA"
"^\d\dXXS"
"^\d\d[B-Z]A"
"^\d\d[B-Z]{2}A"
=====================================
Option Explicit
Function ReComp(str As String, sPattern As String) As Boolean
Dim re As Object
Set re = CreateObject("vbscript.regexp")
re.Global = False
re.Pattern = sPattern
ReComp = re.Test(str)
End Function
=================================
--ron