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

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
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,224,824
Messages
6,181,186
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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