L
Legacy 54891
Guest
Hi
I am trying to write a user defined function to count how many cells contain either "A", "B" or "C" within a given range, but only do this for the odd columns in the range (even if the first column of the range is for example D (i.e. 4) this would still be counted as odd as it is the first column in the range.)
For example =CountAtoC(B1:E2) would return 3 if the following data is stored in the range B1:E2 because there are three cells containing "A", "B" or "C" in the odd columns i.e. 1st and 3rd columns.
B C A E
A F D C
So far I have got the following
but I am struggling where to go next. I suppose I need to figure out which column the current cell being processed is in, but I am not sure how to do this. If I could also get the cell reference of the first (upper left) cell then I would have enought information.
Any help would be greatfully received.
Thankyou.
I am trying to write a user defined function to count how many cells contain either "A", "B" or "C" within a given range, but only do this for the odd columns in the range (even if the first column of the range is for example D (i.e. 4) this would still be counted as odd as it is the first column in the range.)
For example =CountAtoC(B1:E2) would return 3 if the following data is stored in the range B1:E2 because there are three cells containing "A", "B" or "C" in the odd columns i.e. 1st and 3rd columns.
B C A E
A F D C
So far I have got the following
Code:
Function CountAtoC(SelectedRange)
CountAtoC = 0
For Each Cell In SelectedRange
If Cell.Value = "A" Then CountAtoC = CountAtoC + 1
If Cell.Value = "B" Then CountAtoC = CountAtoC + 1
If Cell.Value = "C" Then CountAtoC = CountAtoC + 1
Next Cell
End Function
but I am struggling where to go next. I suppose I need to figure out which column the current cell being processed is in, but I am not sure how to do this. If I could also get the cell reference of the first (upper left) cell then I would have enought information.
Any help would be greatfully received.
Thankyou.