Help multiply cell with several cells

svh105

New Member
Joined
Apr 24, 2022
Messages
5
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,

I am looking for a tool that can automatically multiply one cell with several others depending on the year. I have been able to make it multiply with the correct values individually. But I need it to multiply the price with the value for each year at the same time (see the screenshot I attached), instead of individually as it does now.
I created a loop for it to find the correct year and values to multiply with. But I need help getting it to do exactly what I want. Hope someone is able to help me.

VBA Code:
Sub calculate ()

ActiveCell.Offset(0,1).Select
Dim Cell As Range
    For Each Cell In Range("F5:F24")
    If Cell.Value < Range("B7").Value Then
    
    ElseIf Cell.Value >= Range("B7") Then
        Cell.Offset(0,4).Value = Range("B8") * Cell.Offset(0,1).Value
        
        End If
    Next Cell

End Sub
 

Attachments

  • Skærmbillede 2022-05-08 kl. 19.33.43.png
    Skærmbillede 2022-05-08 kl. 19.33.43.png
    58.6 KB · Views: 10

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
I note that you have 365, so the Filter function should be available to you. If you're ok with a non-VBA solution, and don't mind using some helper columns, then the following gives you what you want (I think). Change the year values in B7 and B12 (the highlighted cells) to demonstrate how it works.

shift.xlsx
ABCDEFGHIJKLMN
1
2
3Example of calculation:Calc #1 filterCalc #2 filter
4YearPrice20170.8720130.83
520000.720180.8820140.84
6Expected lifetime of ivestment (years)10Price in 2019 (Calc #1)20010.7120190.8920150.85
7Year of investment20172725.5420020.7220160.86
8Price of investment400020030.7320170.87
920040.7420180.88
1020050.7520190.89
11Expected lifetime of ivestment (years)75Price in 2019 (Calc #2)20060.76
12Year of investment20133472.7020070.77
13Price of investment1000020080.78
1420090.79
1520100.8
1620110.81
1720120.82
1820130.83
1920140.84
2020150.85
2120160.86
2220170.87
2320180.88
2420190.89
25
Sheet2
Cell Formulas
RangeFormula
I4:J6I4=FILTER($F$5:$G$24,$F$5:$F$24>=$B$7,"")
L4:M10L4=FILTER($F$5:$G$24,$F$5:$F$24>=$B$12,"")
D7D7=PRODUCT($B$8,$J$4:$J$23)
D12D12=PRODUCT($B$13,$M$4:$M$23)
Dynamic array formulas.
 
Upvote 0
Using UDF in cell D7:
=calculate(B7,B8)
Then copy to D12.
with the source code:
VBA Code:
Function Calculate(ByVal year As Range, ByVal price As Range) As Double
Dim cell As Range, n As Double
n = 1
    For Each cell In Range("F5:F24")
        If cell >= year Then n = n * cell.Offset(0, 1)
    Next
Calculate = price * n
End Function

Book1
ABCDEFG
3Example of calculation:
4YearPrice
520000.7
6Expected lifetime of ivestment (years)10Price in 2019 (Calc #1)20010.71
7Year of investment20172,725.5420020.72
8Price of investment400020030.73
920040.74
1020050.75
11Expected lifetime of ivestment (years)75Price in 2019 (Calc #2)20060.76
12Year of investment20133,472.7020070.77
13Price of investment1000020080.78
1420090.79
1520100.8
1620110.81
1720120.82
1820130.83
1920140.84
2020150.85
2120160.86
2220170.87
2320180.88
2420190.89
Sheet2
Cell Formulas
RangeFormula
D7,D12D7=calculate(B7,B8)
 
Upvote 0
Another formula option, without the helper cells
+Fluff v1.xlsm
ABCDEFG
3Example of calculation:
4YearPrice
520000.7
6Expected lifetime of ivestment (years)10Price in 2019 (Calc #1)20010.71
7Year of investment20172725.5420020.72
8Price of investment400020030.73
920040.74
1020050.75
11Expected lifetime of ivestment (years)75Price in 2019 (Calc #2)20060.76
12Year of investment20133472.7020070.77
13Price of investment1000020080.78
1420090.79
1520100.8
1620110.81
1720120.82
1820130.83
1920140.84
2020150.85
2120160.86
2220170.87
2320180.88
2420190.89
Sheet1
Cell Formulas
RangeFormula
D7D7=PRODUCT(B8,FILTER(G5:G24,F5:F24>=B7))
D12D12=PRODUCT($B$13,FILTER(G5:G24,F5:F24>=B12))
 
Upvote 0
Another formula option, without the helper cells
+Fluff v1.xlsm
ABCDEFG
3Example of calculation:
4YearPrice
520000.7
6Expected lifetime of ivestment (years)10Price in 2019 (Calc #1)20010.71
7Year of investment20172725.5420020.72
8Price of investment400020030.73
920040.74
1020050.75
11Expected lifetime of ivestment (years)75Price in 2019 (Calc #2)20060.76
12Year of investment20133472.7020070.77
13Price of investment1000020080.78
1420090.79
1520100.8
1620110.81
1720120.82
1820130.83
1920140.84
2020150.85
2120160.86
2220170.87
2320180.88
2420190.89
Sheet1
Cell Formulas
RangeFormula
D7D7=PRODUCT(B8,FILTER(G5:G24,F5:F24>=B7))
D12D12=PRODUCT($B$13,FILTER(G5:G24,F5:F24>=B12))
Nice!
 
Upvote 0

Forum statistics

Threads
1,214,904
Messages
6,122,169
Members
449,070
Latest member
webster33

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