Create a Macro to ask and question, and then update cells

hbarnett

New Member
Joined
Jan 21, 2021
Messages
7
Office Version
  1. 365
Platform
  1. Windows
I would like to create a macro that ask a question, question I am looking to ask is Please enter percent
Once the user enters in a percent say 25
I would then like it to update a range of cells that already have information in them

So for example I have these rows which has a unit price in them.

When the user enters 25, it will change the 1st row to 1.25, the second row to 2.50 etc.

Unit Price
$1.00
$2.00
$3.00
$4.00
$5.00
$6.00
$7.00
$8.00
$9.00
$10.00
 
Yes it had a word missing, try this version.

VBA Code:
Sub t3()
Dim nr As Long, pct As Double, fn As Range, c As Range
nr = Application.InputBox("Please enter a percentage as a whole number, e.g. 25", "PERCENTAGE", Type:=1)
pct = nr / 100
With ActiveSheet
    Set fn = .Rows(3).Find("Unit Price", , xlValues)
        If Not fn Is Nothing Then
            For Each c In fn.Offset(1).Resize(10)
                If c.Value > 0 Then
                    c = c.Value + (c.Value * pct)
                End If
            Next
        End If
End With
End Sub
 
Upvote 0

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Thank you so much, you are a god among man.

I really appreciate all of your help
 
Upvote 0
Good Morning,

One more question is it possible after the user puts in the quantity and it makes the change on the spreadsheet, that it pops up with another box to say Accept Change Yes/No

And if the users selects No it undoes the change and reverts back to the original number?
 
Upvote 0
VBA Code:
Sub t4()
Dim nr As Long, pct As Double, fn As Range, c As Range, rval As Variant
nr = Application.InputBox("Please enter a percentage as a whole number, e.g. 25", "PERCENTAGE", Type:=1)
pct = nr / 100
With ActiveSheet
    Set fn = .Rows(3).Find("Unit Price", , xlValues)
        rval = fn.Offset(1).Resize(10).Value
        If Not fn Is Nothing Then
            For Each c In fn.Offset(1).Resize(10)
                If c.Value > 0 Then
                    c = c.Value + (c.Value * pct)
                End If
            Next
        End If
        q = MsgBox("Accept changes?", vbQuestion + vbYesNo, "VALIDATE")
        If q = vbNo Then fn.Offset(1).Resize(10) = rval
End With
End Sub
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

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