Multiplying a Cell base on Adjacent Column

madhuchelliah

Board Regular
Joined
Nov 22, 2017
Messages
226
Office Version
  1. 2019
Platform
  1. 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

GH
N2
N3
N2
Y1
Y2
Y3
N2
N2
N2
Y1
N5
Y1
Y2
Y3
N1
Y1

<tbody>
</tbody>
G
H
N2
N3
N2
Y2
Y4
Y6
N2
N2
N2
Y2
N5
Y5
Y10
Y15
N1
Y1

<tbody>
</tbody>
 
Sorry I couldn't be of more assistance
 
Upvote 0

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
Hello Fluff, I identified the issue. Some of the cells in the H column contains TEXT values. Is there any fix to solve this?. Some times i am text values in H column
 
Upvote 0
Hi, here is another option that you can try..

Code:
Sub m()
Dim a, i As Long, m As Double
a = Range("G1:H" & Range("G" & Rows.Count).End(xlUp).Row).Value
For i = 1 To UBound(a)
  If IsNumeric(a(i, 2)) Then
    If UCase(a(i, 1)) = "N" Then m = a(i, 2)
    If UCase(a(i, 1)) = "Y" Then a(i, 2) = a(i, 2) * m
  End If
Next i
Range("G1:H1").Resize(UBound(a)).Value = a
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,972
Messages
6,127,997
Members
449,414
Latest member
sameri

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top