NESTED IF/THEN STATEMENT
Copy link to clipboard
Copied
Is it possible to create an if/then statement where if B4 = B3+1 than display the first number and the last number with a dash in between and if not then put a dash after the number in the cell. Result I am looking for based on the below would be: 64, 114-118, 282-284, 288-290. Any help is greatly appreciated.
Example:
Cell B3 is 64, Cell B4 is 114 and so on.
MAP |
64 |
114 |
115 |
116 |
117 |
118 |
282 |
283 |
284 |
288 |
289 |
290 |
Copy link to clipboard
Copied
Is it possible to create an if/then statement where if B4 = B3+1 than display the first number and the last number in the sequence with a dash in between and if not then put a comma after the number in B3. Result I am looking for based on the below would be: 64, 114-118, 282-284, 288-290. Any help is greatly appreciated.
Example:
Cell B3 is 64, Cell B4 is 114 and so on.
MAP |
64 |
114 |
115 |
116 |
117 |
118 |
282 |
283 |
284 |
288 |
289 |
290 |
Copy link to clipboard
Copied
The answer is that you can create a script that arranges a list of numbers into a list of ranges. Not exactly an "if" statement, but there will be "if"s 😉
Here's an example:
var aNums = [1,2,3,14,16,17,20];
var aCollect = [];
aNums.forEach(function(a,i,lst){
// If first or non-consecutive number, then push onto collection
if(!i || (lst[i-1]!= (a-1))) aCollect .push([a]);
// If consecutive number, push onto (keep with)last element in collection
else aCollect [aCollect .length-1].push(a);
})
// convert to range.
var aRanges = aCollect .map(function(a){return (a.length == 1)?a[0]:a[0] + "-" + a.pop();})
Use the Acrobat JavaScript Reference early and often

