6 Replies Latest reply on Jun 24, 2014 1:30 AM by try67

# How do I count/add fields with numbers and fields with letters?

This is an attendance calendar I'm making for my work.

Cells in CLIENT A column will be marked with either a number ( >0, indicating how many hours attended) or a letter (A = absent, H = Holiday).

I need 2 formulas/scripts I suppose:

1) I would like cell DP1 to represent how many cells in the CLIENT A column are marked only with a number >0 -indicating how many days were attended, not how many total hours there are.

2) I would like cell DA1 to represent how many cells in the CLIENT A column are marked only with the letter A -indicating how many days were not attended.

• ###### 1. Re: How do I count/add fields with numbers and fields with letters?

Let's say there are 20 fields in the column. In that case you can use these scripts:

Custom calculation script for "DPA"

```var total = 0;
for (var i=1; i<=20; i++) {
var v = +this.getField("CA"+i).value;
if (isNaN(v)==false && v>0)
total++;
}
event.value = total;
```

Custom calculation script for "DPB"

```var total = 0;
for (var i=1; i<=20; i++) {
var v = this.getField("CA"+i).value;
if (v=="A")
total++;
}
event.value = total;
```
• ###### 2. Re: How do I count/add fields with numbers and fields with letters?

Thank you for help! I'll try this out when I get the chance!

• ###### 3. Re: How do I count/add fields with numbers and fields with letters?

Thanks! I finally got around to implementing this and it works perfectly! Sorry for the delayed response.

I just have 2 more details that need to be ironed out if you don't mind:

1) For the second script, instead of just uppercase, I would like it to count both lowercase "a" and uppercase "A" (whichever the user happens to input).

2) When I print this document without filling in any information, the DP1 and DA1 cells will show "0.00". How do get these cells to print blank while keeping the scripts?

• ###### 4. Re: How do I count/add fields with numbers and fields with letters?

1) Change line #4 to:

if (v.toUpperCase()=="A")

2) Is this just a printing issue, or do you want to not show anything in the fields if the value is 0, in all cases?

• ###### 5. Re: How do I count/add fields with numbers and fields with letters?

1) Thanks!

2) Yes, just a printing issue.  It doesn't matter what it says when on the computer (as long as it's the correct data of course!)

• ###### 6. Re: How do I count/add fields with numbers and fields with letters?

You can use a Document Will Print script to set those fields to non-printable if their values are zero, or to printable otherwise.