VBA Code to Multiple Specific Cells by Cell Value

rbellavance22

New Member
Joined
Aug 8, 2019
Messages
14
Hello,

I have a worksheet with various dollar amounts in multiple cells.

I would like to come up with a VBA Code to increase specific cells (B14, C14, D14, B15, C15, D15) by a percentage that is set by a cell value (cell A1).

Any help would be greatly appreciated!
 

alansidman

Well-known Member
Joined
Feb 26, 2007
Messages
5,044
Office Version
2019
Platform
Windows
Code:
Option Explicit


Sub test1()
    Dim m As Variant
    Dim c As Range
    Dim rng As Range
    m = Range("A1")
    Set rng = Range("B14:D14", "B15:D15")
    For Each c In rng
        c = c * m
    Next c
End Sub
 

rbellavance22

New Member
Joined
Aug 8, 2019
Messages
14
This is great. Thank you so much.

One quick question, since this a monetary value is there anyway to round up to the nearest nickel?

It standard formulas, it is typically =CEILING(sum(X*X),0.05), I'm just not sure where it goes here.

Code:
Option Explicit


Sub test1()
    Dim m As Variant
    Dim c As Range
    Dim rng As Range
    m = Range("A1")
    Set rng = Range("B14:D14", "B15:D15")
    For Each c In rng
        c = c * m
    Next c
End Sub
 

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
41,816
Office Version
365
Platform
Windows
.. increase specific cells ... by a percentage that is set by a cell value (cell A1).
I take that to mean that A1 might contain 10% and in that case if B14 contains 200 you want to change it to 220.
If that is so, try
Code:
Sub IncreaseByPercentage()
  With Range("B14:D15")
    .Value = Evaluate("ceiling((1+A1)*" & .Address & ",0.05)")
  End With
End Sub
 

rbellavance22

New Member
Joined
Aug 8, 2019
Messages
14
Thank you very much for the response. I am almost there.

It is rounding perfectly, however it is returning B14, C14 and D15 back with the same number.

The current values (after slight adjustments) are:
A1's value is 1.04
B14' value is 17
C14's value is 10
D14's value is 8

The goal is to change the values to:
B14: 17.70
C14: 10.4
D14: 8.35

I take that to mean that A1 might contain 10% and in that case if B14 contains 200 you want to change it to 220.
If that is so, try
Code:
Sub IncreaseByPercentage()
  With Range("B14:D15")
    .Value = Evaluate("ceiling((1+A1)*" & .Address & ",0.05)")
  End With
End Sub
 
Last edited:

Peter_SSs

MrExcel MVP, Moderator
Joined
May 28, 2005
Messages
41,816
Office Version
365
Platform
Windows
A1's value is 1.04
OK, I didn't know that you already had the 1.04 and thought you probably had just 0.04 so I added the 1 in my code. :)

Never-the-less my code should not have returned the same number back in B14:D15 (unless they already contained zero)

Try the replacement line:
Code:
.Value = Evaluate("ceiling(A1*" & .Address & ",0.05)")
 
Last edited:

rbellavance22

New Member
Joined
Aug 8, 2019
Messages
14
Thank you very much for the update.

Unfortunately when I run it, I am still getting the same values. B14 is perfect, however the other cells are returning the same value as B14.

OK, I didn't know that you already had the 1.04 and thought you probably had just 0.04 so I added the 1 in my code. :)

Never-the-less my code should not have returned the same number back in B14:D15 (unless they already contained zero)

Try the replacement line:
Code:
.Value = Evaluate("ceiling(A1*" & .Address & ",0.05)")
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,562
Office Version
365
Platform
Windows
How about
Code:
Sub IncreaseByPercentage()
  With Range("B14:D15")
    .Value = Evaluate("if({1},ceiling(A1*" & .Address & ",0.05))")
  End With
End Sub
 

rbellavance22

New Member
Joined
Aug 8, 2019
Messages
14
Great, thank you for your help.

One last thing: if I wanted to add two additional cells, C45 and D81, how would I do that?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
30,562
Office Version
365
Platform
Windows
You would have to do them separately, as evaluate doesn't seem to like non-contiguous ranges
 

Forum statistics

Threads
1,078,492
Messages
5,340,686
Members
399,389
Latest member
JayNExcel

Some videos you may like

This Week's Hot Topics

  • Problem with Radio Button's format control
    I am creating an employee evaluation template (a sample is below) Column A is the category Column B, C D, E and F will be ratings (unacceptable...
  • Last Display on userform to a Listbox
    [CODE=vba] lstdisplay.ColumnCount = 15 lstdisplay.RowSource = "A1:O600000" [/CODE] So when i do this it Displays everything on the sheet i am...
  • Rename and move files to a new location
    Dear all, I have an excel file with the following information. The actual file name is at column A but i want to rename it using the following...
  • Help with True/False Formula
    Hello! Am stumped how to fix this formula, in which my result returns 'True', but it should return False. =IF(AG2=True...
  • Clear extra characters from a provided range of cells
    Dear All, I have following code which gives me desired output to remove extra characters from a provided range. But it takes too much time when...
  • Help with Current and highest streaks
    Hi there, I've just joined the forum and this is my first post. I've already spent quite a bit of time searching the net and this forum for a...
Top