VBA for Iferror with pop up and open field

ChrisM88

New Member
Joined
Sep 14, 2023
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hi,
I used to have a piece of code which allowed me to select a series of cells and upon running the macro, it would update each formula with an IFERROR prefix, with a popup box to confirm what to return if the cell was in error, so for example, i could put 0 or "n/a".
Does anyone have something which does this job?

Thanks in advance
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Welcome to the Board!

Maybe something like this:
VBA Code:
Sub CreateIFERRORFormulas()

    Dim cell As Range
    Dim ret As String
    
    Application.ScreenUpdating = False
    
'   Prompt user for what to return
    ret = InputBox("What would you like to return in case of an error?")
    
'   Loop through all cells in selection
    For Each cell In Selection
'       Turn formula into IFERROR formula
        If Left(cell.Formula, 1) = "=" Then
            cell.Formula = "=IFERROR(" & Mid(cell.Formula, 2, Len(cell.Formula)) & "," & Chr(34) & ret & Chr(34) & ")"
        End If
    Next cell
    
    Application.ScreenUpdating = True
    
End Sub
 
Upvote 0
Welcome to the Board!

Maybe something like this:
VBA Code:
Sub CreateIFERRORFormulas()

    Dim cell As Range
    Dim ret As String
   
    Application.ScreenUpdating = False
   
'   Prompt user for what to return
    ret = InputBox("What would you like to return in case of an error?")
   
'   Loop through all cells in selection
    For Each cell In Selection
'       Turn formula into IFERROR formula
        If Left(cell.Formula, 1) = "=" Then
            cell.Formula = "=IFERROR(" & Mid(cell.Formula, 2, Len(cell.Formula)) & "," & Chr(34) & ret & Chr(34) & ")"
        End If
    Next cell
   
    Application.ScreenUpdating = True
   
End Sub
Perfect, really appreciate the response!!!
 
Upvote 0
You are welcome.
Glad I was able to help!
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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