VBA - Inserting a ROUND function into some IFERROR code

Joined
Mar 17, 2013
Messages
9
Hello :)

I would like some help please regarding VBA code. I have found some lines of code that work and add an IFERROR statement to whatever I have selected at the time on my worksheet, adding the text 'No Data' if there is an error. This works and I am happy with it. Here follows is the code:

Code:
Sub InsertIFERROR()
    Dim R As Range
    For Each R In Selection.SpecialCells(xlCellTypeFormulas)
        R.Formula = "=IFERROR(" & Mid(R.Formula, 2) & ",""No Data"")"
    Next R
End Sub

However I would like to add into this another formula which I have tried to do but my attempts lead to an error. The function I wish to add is the ROUND function which rounds the data to one decimal place e.g. on cell A1 it would be =ROUND(A1,1).

So if anybody can help insert the ROUND function into this vba code, or suggest a better way to wrap IFERROR to my selection and at the same time ROUND the data to 1 decimal place I would be very much obliged.

As a side I select cells B2:CE248 before running this so if it is more streamlined to state absolutly the cell range rather than applying to my higlighted selection then please feel free to ammed as apporpite. I am an absolute beginner with VBA.

To anybody who reads this, thank you for your time.
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Code:
Sub InsertIFERROR()
On Error Resume Next
    Dim R As Range
    For Each R In Selection.SpecialCells(xlCellTypeFormulas)
        R.Formula = "=IFERROR(ROUND(" & Mid(R.Formula, 2) & ",1),""No Data"")"
    Next R
End Sub
 
Upvote 0
Try something like this assuming the formulas are not already wrapped with the IFERROR

R.Formula = "=IFERROR(ROUND(" & Mid(R.Formula, 2) & ",1),""No Data"")"
 
Upvote 0
Dear Scott Huish and AlphaFrog. I wish to offer my gratitude to the both of you. Your answers are exactly perfect and work like a charm. Thank you ever so much. Christopher :)
 
Upvote 0

Forum statistics

Threads
1,214,534
Messages
6,120,080
Members
448,943
Latest member
sharmarick

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