Hello everyone,
I have a problem that may seem a bit unusual, but I hope someone on this board can help me. I have several columns (can range from 2 to 100+ depending on the data) that have the values either 0 or 1 (absence/presence) for each row (up to 150 rows). I want to count, within each row, how many times the adjacent cells differ in their values, and report the total number of times the changes occur. To explain further, if for Row1 the value changes from 0 to 1 at Column3, I want to count this. If the value changes from 1 to 0 at Column7, I want to count this and add to the first count. And so on till the last column.
If someone could provide a macro to do this, I would be be grateful for your help. Thank you.
Example input:
<tbody>
</tbody>
Desired output:
<tbody>
</tbody>
(The NA need to be skipped and not counted/reported.)
I have a problem that may seem a bit unusual, but I hope someone on this board can help me. I have several columns (can range from 2 to 100+ depending on the data) that have the values either 0 or 1 (absence/presence) for each row (up to 150 rows). I want to count, within each row, how many times the adjacent cells differ in their values, and report the total number of times the changes occur. To explain further, if for Row1 the value changes from 0 to 1 at Column3, I want to count this. If the value changes from 1 to 0 at Column7, I want to count this and add to the first count. And so on till the last column.
If someone could provide a macro to do this, I would be be grateful for your help. Thank you.
Example input:
Data | Col1 | Col2 | Col3 | Col4 | Col5 | Col6 | Col7 | Col8 | Col10 |
Row1 | 1 | 1 | 1 | 1 | 0 | 0 | 1 | 1 | 1 |
Row2 | 0 | 0 | 0 | 0 | NA | 1 | 1 | 1 | 1 |
Row3 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Row4 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Row5 | 1 | 1 | 1 | 1 | NA | 0 | 0 | 1 | 1 |
Row6 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 |
Row7 | 0 | 0 | 0 | 0 | 0 | 0 | NA | 1 | 1 |
Row8 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 | 0 |
Row9 | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 | 0 |
<tbody>
</tbody>
Desired output:
Row1 | 2 Changes |
Row2 | 1 Changes |
Row3 | 0 Changes |
Row4 | 0 Changes |
Row5 | 2 Changes |
Row6 | 3 Changes |
Row7 | 1 Changes |
Row8 | 0 Changes |
Row9 | 5 Changes |
<tbody>
</tbody>
(The NA need to be skipped and not counted/reported.)