Rounding Macro Code

kluitna

Board Regular
Joined
Mar 10, 2002
Messages
75
Here is some code I have tried to right for my rounding portion of a macro. The problem is getting the active cell selected. This is there a way to tell Excel that I am looking for the current worksheet. The problem I am having is I want this macro to work on every work sheet and there can be any where from 5 to 256 worksheets in a workbook that this macro will work with.

Anyone out there have any suggestions?

Any help is greatly appreciated

For i = 0 To 35
Dim Rnd As String
If Rnd = blank Then End
Rnd = Worksheets.Cells(16 + i, 9)
Range.Rnd.Select
ActiveCell.FormulaR1C1 = "=ROUND(RC[-2]*RC[-3],4)"
Next i
End Sub
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.
Generally if I'm running code for the worksheet I'm currently in I use "ActiveSheet"

This would mean that you would select the sheet you want before running the code.

If you want to cycle through and run the code on each worksheet in your workbook, you would want to set up a loop through the worksheets collection.
 
Upvote 0
if your just wanting to run the code when your on the sheet

Sub testi()
Set iSht = ActiveSheet
For i = 0 To 35
If iSht.Cells(16 + i, 9).Value = Empty Then GoTo iend
iSht.Cells(16 + i, 9).Value = "=ROUND(RC[-2]*RC[-3],4)"
Next i
iend:
End Sub

else if you want to run the macro on multiple sheets at once you may want an array of the sheets.

Brett
 
Upvote 0

Forum statistics

Threads
1,224,879
Messages
6,181,531
Members
453,054
Latest member
ezzat

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