Simple VBA query

jonny1984

New Member
Joined
Apr 27, 2012
Messages
20
Office Version
  1. 2016
Platform
  1. Windows
Hi

I have a very simple query for something I am trying to do in Excel using VBA and hoping someone can help

In a spreadsheet lets say I have the following values in cells B5:B10

A B

5 4
6 9
7 5
8 6
9 11
10 5


I am looking for code that would define a percentage and then multiply each cell by a given percentage. For example lets say I had three percentage values ... 5%, 10%, 20%

I want to define those at the beginning of my code, and then say do

Cell B5 should be the value * percentage_2 (in this case 10%)
Cell B6 should be the value * percentage_3 (in this case 20%)
Cell B7 should be the value * percentage_1 (in this case 5%)

I'd like to define the Percentages at the start so that I can change those percentages and the code will run with new percentgae values .. but keeping the individual cells multiplied by the "correct percentage (eg "percentage_2")


I'm not sure I've explained that well !! Hopefully someone can see / understand what im trying to do !!

Thanks in advance,
JOnny
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
This is what the basic code should look like
Code:
Sub MulInp()
    Per1 = InputBox("Enter the first percentage", "PERCENTAGE 1")
    per2 = InputBox("Enter the Second percentage", "PERCENTAGE 2")
    per3 = InputBox("Enter the Third percentage", "PERCENTAGE 3")
    
    Range("B5").Value = Range("B5").Value * per2 / 100
    Range("B6").Value = Range("B6").Value * per3 / 100
    Range("B7").Value = Range("B7").Value * per2 / 100
End Sub

in entering the percentages, just enter 20 and not 20% for example, the % part is taken care of by the "/100"
 
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

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