macro to add markup

SHBeck

Board Regular
Joined
Dec 2, 2012
Messages
145
I am looking for some help to build a macro that will add a variable % of markup to all numbers in column D, the variable % is = Textbox2 input. Thank you
 

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Below is some code that I placed in the TextBox2 "LostFocus" event. It will only execute the macro once you leave or de-select the text box.

Code:
If TextBox2.Value <> "" Then
    For Each c In Worksheets("Sheet1").Range("D2:D100")
        If c <> "" Then
        CountRow = c.Row
        c = c * (1 + (TextBox2.Value / 100))
        Worksheets("Sheet1").Cells(CountRow, 4).Value = c
        End If
    Next c
End If

This will mark-up the values in column D. If you want to retain the original values and show the marked-up value in the adjacent column, you should change (CountRow,4) to (CountRow,5) in the above code.

Let me know if this works for you. It worked great in my test sheet.
 
Upvote 0
You can use this in your textbox module to calculate on "Enter" or box exit.

Code:
Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)    If KeyCode = vbKeyReturn Then
        Worksheets("Sheet1").Range("a1").Activate
    End If
End Sub
 
Upvote 0

Forum statistics

Threads
1,202,990
Messages
6,052,949
Members
444,621
Latest member
MIKOLAJ_R

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