bulk re-enter formulas in cell to fix #NAME? error

jackms

New Member
Joined
Dec 28, 2005
Messages
35
Office Version
  1. 2016
Platform
  1. Windows
We have a process where we end up with a workbook with formulas full of references to range names that don't exist in that workbook. As expected, the cells all show #NAME?
We then move the sheets from that workbook to another workbook where those names do exist.
EXAMPLE: WorkbookA has formula =RangeNameA but that range name does not exist in WorkbookA
But then we move the sheets from WorkbookA into WorkBookB. And RangeNameA does exist in WorkbookB

Problem is that even after moving the sheets, the cells still show #NAME? CalculateFull and CalculateFullRebuild don't fix the errors. The only way I know to fix this is to re-enter the formula in each cell.
VBA Code:
For Each c In ws.UsedRange.Cells
    c.Formula = c.Formula
Next c

But there are many, many cells and this method takes too long. Is there a way I can fix the #NAME? in bulk for all the cells in these sheets?
 
Thanks. Problem is, that since these are large sheets, I need something more efficient than looping through one cell at a time.
This will move all the formulas to the new sheet, without loooping
VBA Code:
newSheet.Range("A1:AZ999").Formula = oldSheet.Range("A1:AZ999").Formula
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Have never had a similar problem but this may work for you.
Put the names of the sheets with the missing reference to the named ranges in the array.

VBA Code:
Sub UpdateFormulas()

    Dim oWs As Worksheet, shts, f

    shts = Array("Sheet1", "Sheet5")        ' << change to suit

    Application.Calculation = xlCalculationManual
    Application.EnableEvents = False
    shts = Join(shts, ":")
    For Each oWs In ThisWorkbook.Worksheets
        With oWs
            If InStr(LCase(":" & shts & ":"), LCase(":" & .Name & ":")) > 0 Then
                With .UsedRange
                    f = .Formula
                    .Formula = f
                End With
            End If
        End With
    Next oWs
    Application.EnableEvents = True
    Application.Calculation = xlCalculationAutomatic

End Sub
Great! It worked! Thank you!!!!

For future reference, here's the bit of code that contains the solution
VBA Code:
                With .UsedRange
                    f = .Formula
                    .Formula = f
                End With
 
Upvote 0
You are welcome and thanks for letting us know.
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,171
Members
453,021
Latest member
Justyna P

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