VBA code to divide a range of cells by 1000 with command button

marcapicella

New Member
Joined
Jun 4, 2015
Messages
3
Hello,

I need help with dividing a range of cells (say G7:K16) by using a VBA command button. I will also be creating many of these command buttons in different sheets but they will serve the same purpose (dividing different ranges by 1000).

Thanks for your help!
 

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.
Upvote 0
I guess you're not interested in the pastespecial/divide technique. I believe the code shown in that thread was meant to do every cell in every sheet.

Try putting something simple in your command button and improve it from there, maybe this:

Code:
Dim oCell As Range

For Each oCell In Selection
    oCell.Value = oCell.Value / 1000
Next oCell

Select/Highlight the range you want to multiply then click the button.
 
Upvote 0
I guess you're not interested in the pastespecial/divide technique. I believe the code shown in that thread was meant to do every cell in every sheet.

Try putting something simple in your command button and improve it from there, maybe this:

Code:
Dim oCell As Range

For Each oCell In Selection
    oCell.Value = oCell.Value / 1000
Next oCell

Select/Highlight the range you want to multiply then click the button.
This non-looping macro should be faster...

Sub DivideSelectionBy1000()
Selection = Evaluate(Replace("IF(ISNUMBER(@),@/1000,IF(@="""","""",@))", "@", Selection.Address))
End Sub
 
Upvote 0
Fantastic! Thank you!!


I guess you're not interested in the pastespecial/divide technique. I believe the code shown in that thread was meant to do every cell in every sheet.

Try putting something simple in your command button and improve it from there, maybe this:

Code:
Dim oCell As Range

For Each oCell In Selection
    oCell.Value = oCell.Value / 1000
Next oCell

Select/Highlight the range you want to multiply then click the button.
 
Upvote 0

Forum statistics

Threads
1,203,082
Messages
6,053,419
Members
444,662
Latest member
AaronPMH

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