madhuchelliah
Board Regular
- Joined
- Nov 22, 2017
- Messages
- 226
- Office Version
- 2019
- Platform
- Windows
Hello Folks,I have a very complex requirement. I need a macro to multiply based on some conditions. I have a two column one is filled with "Y" and "N" letters another one is filled with numbers. My requirement is to identify all the "Y" succeeded by "N" and multiply the value of adjacent cell to 'N" with values of cells adjacent to "Y". There could be lot of combinations of N decent by Y. See the example below.
Source Result
[TABLE="class: grid, width: 100, align: left"]
<tbody>[TR]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 100, align: center"]
<tbody>[TR]
[TD="align: center"]G
[/TD]
[TD="align: center"]H
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]4
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]6
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]10
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]15
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
</tbody>[/TABLE]
Source Result
[TABLE="class: grid, width: 100, align: left"]
<tbody>[TR]
[TD="align: center"]G[/TD]
[TD="align: center"]H[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
</tbody>[/TABLE]
[TABLE="class: grid, width: 100, align: center"]
<tbody>[TR]
[TD="align: center"]G
[/TD]
[TD="align: center"]H
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]3[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]4
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]6
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]2[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]5[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]5
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]10
[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]15
[/TD]
[/TR]
[TR]
[TD="align: center"]N[/TD]
[TD="align: center"]1[/TD]
[/TR]
[TR]
[TD="align: center"]Y[/TD]
[TD="align: center"]1[/TD]
[/TR]
</tbody>[/TABLE]