Vba Code to Remove #Name? error in all cells entire worksheet

Joined
Jan 11, 2024
Messages
19
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hello Everyone,
I am unable to remove #Name? error in my excel sheet. I need any vba code show that the cells can show actual text including character =
See the screenshot of the error.
Error.jpg
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
You don't need a macro to see that. Just press Ctrl-~ to show the cell contents, and then press it again when you're finished.
 
Upvote 0
You don't need a macro to see that. Just press Ctrl-~ to show the cell contents, and then press it again when you're finished.
Yes but it needs to be done in every sheets multiple times if i have 200 sheets in the workbook with same error. So thats y i need a shortcut or vba. Any suggestion
 
Upvote 0
As to a shortcut, you could use GoTo.
  1. Press F5 to bring up the dialog box,
  2. click the "Special" button,
  3. click the "Formulas" radio button
  4. under "Formulas" take the ticks out of "Numbers", "Text", and "Logicals" (so now only "Errors" has a tick in that group), then
  5. click the "OK" button.
The cells should now be selected, and once you've checked that you've got the right cells, you can just press the Delete key on the keyboard.
 
Upvote 0
... or would this code suit you better?
VBA Code:
Sub DeleteNameErrors()
    Dim wksToCheck As Worksheet
    Dim rngCell As Range
    Dim xlcPrev As XlCalculation
    '
    xlcPrev = Application.Calculation
    Application.Calculation = xlCalculationManual
    For Each wksToCheck In ThisWorkbook.Worksheets
        For Each rngCell In wksToCheck.UsedRange
            If rngCell.HasFormula Then
                If (rngCell.Text = "#NAME?") Then
                    If (rngCell.Formula2R1C1 = "=yes") Then
                        rngCell.ClearContents
                    End If
                End If
            End If
        Next
    Next
    Application.Calculation = xlcPrev
    MsgBox "Finished!", vbInformation + vbOKOnly, "Delete Name Errors"
End Sub
 
Upvote 0
I dont want to delete #Name? error , I want to show actual text Ctrl~ worked! but this vba not working
Ctrl~ worked . Go to also worked
 
Upvote 0
Okay, if you just want to show the actual text, rather than the #NAME? error, this code will do that.
VBA Code:
Sub ShowNameErrors()
    Dim wksToCheck As Worksheet
    Dim rngCell As Range
    Dim xlcPrev As XlCalculation
    '
    xlcPrev = Application.Calculation
    Application.Calculation = xlCalculationManual
    For Each wksToCheck In ThisWorkbook.Worksheets
        For Each rngCell In wksToCheck.UsedRange
            If rngCell.HasFormula Then
                If (rngCell.Text = "#NAME?") Then
                    rngCell.Value = "'" & rngCell.Formula2R1C1
                End If
            End If
        Next
    Next
    Application.Calculation = xlcPrev
    MsgBox "Finished!", vbInformation + vbOKOnly, "Show Name Errors"
End Sub
 
Upvote 0
Finally it worked with some modifications

Sub ShowNameErrors()
Dim wksToCheck As Worksheet
Dim rngCell As Range
Dim xlcPrev As XlCalculation

' Store the previous calculation mode
xlcPrev = Application.Calculation
Application.Calculation = xlCalculationManual

' Loop through each worksheet in the workbook
For Each wksToCheck In ThisWorkbook.Worksheets
' Loop through each cell in the used range of the worksheet
For Each rngCell In wksToCheck.UsedRange
' Check if the cell contains a formula and if its text is "#NAME?"
If rngCell.HasFormula Then
If rngCell.Text = "#NAME?" Then
' Replace the cell value with the formula preceded by an apostrophe
rngCell.Value = "'" & rngCell.Formula
End If
End If
Next rngCell
Next wksToCheck

' Restore the previous calculation mode
Application.Calculation = xlcPrev

' Display a message box to indicate completion
MsgBox "Finished!", vbInformation + vbOKOnly, "Show Name Errors"
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,110
Messages
6,123,146
Members
449,098
Latest member
Doanvanhieu

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