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
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
VBA Code:
Sub t()
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(1).Find("Unit Price", , xlValues)
        If Not fn Is Nothing Then
            For Each c In Intersect(.UsedRange.Offset(1), Columns(fn.Column))
                If c.Value > 0 Then
                    c = c.Value + (c.Value * pct)
                End If
            Next
        End If
End With
End Sub
 
Upvote 0
JLGWhiz - thank you for you help, I am getting an error on the c=c.value + (c.value *pct) part though.

Here is a screen shot of the file I am working on. I change the .rows(1) to .row(3) as there is where the unit price is

1611258154621.png
 
Upvote 0
If the error is type mismatch, it is likely because the Intersect function is not valid with the headers bing in row 3. The code below should fix that.

VBA Code:
Sub t()
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 Intersect(.UsedRange.Offset(3), Columns(fn.Column))
                If c.Value > 0 Then
                    c = c.Value + (c.Value * pct)
                End If
            Next
        End If
End With
End Sub
 
Upvote 0
We are close, we are getting the run time error when it column 14, as that column says Grand Total

So I only need it do columns 4 through 13
 
Upvote 0
i assume you mean rows 4:13.

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 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

Forum statistics

Threads
1,215,366
Messages
6,124,514
Members
449,168
Latest member
CheerfulWalker

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