VBA Multiplying Help!!

csijenna

New Member
Joined
Jan 9, 2024
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I am trying to set up a spreadsheet that will automatically multiply the entry in a cell by the price listed in another cell and display the total price in the cell instead of the previously entered amount purchased. For Example: Sailcraft permits are $250 each. I want to enter that someone purchased 2 and that 2 to automatically change to $500.
I am stumped. Does anyone have a code for VBA that would work for this? Ideally I would do this for multiple columns just changing the cell the amount is in for the multiplying and do it only for a range per column so that I can total each column at the bottom.
Thank you all in advance!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Welcome to the Forum!

It's easy enough to do this using VBA. But why on earth would you want to do this?

Purchase orders, invoices etc show unit prices and numbers of units because it makes sense to do this- the number of units is a key piece of information. Why would you want to overwrite these numbers?

ABC
1PriceTotal
2$250$250<-- after entering 1
3$50$100<-- after entering 2
4$100$300<-- after entering 3
Sheet1

VBA Code:
'In the relevant sheet module
Private Sub Worksheet_Change(ByVal Target As Range)

    Dim rng As Range, r As Range
    
    Set rng = Intersect(Target, Range("B2:B4"))
    
    If Not rng Is Nothing Then
        Application.EnableEvents = False
        For Each r In rng
            r.Value = r.Value * r.Offset(, -1).Value
        Next r
        Application.EnableEvents = True
    End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,169
Members
453,021
Latest member
Justyna P

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