.formula has VBA error when using special characters

tderb001

New Member
Joined
Oct 12, 2020
Messages
2
Office Version
  1. 365
  2. 2019
  3. 2016
  4. 2013
  5. 2010
Platform
  1. Windows
I have an excel macro that loops through table body cells on each worksheet and inserts a cell formula using a combination of text strings. There are three worksheets.

The macro works fine on worksheet 1 and 3, but on worksheet 2, the macro errors out with an application-defined or object-defined error. The error goes away when I remove all special characters from the formula text strings.

The special characters I use are ( " and @ . I have tried using the special characters within quotations like "@" and I have tried using the Chr(64) function to insert the special character. The macro works fine in Excel 2016, but it is breaking in Excel 2010. What is going wrong?
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.
HERE IS THE MACRO THAT LOOPS THROUGH EACH SHEET AND RUNS THE MACRO TO UPDATE FORMULAS

Sub UpdateFormulas()
Application.ScreenUpdating = False
For Each xSheet In ThisWorkbook.Worksheets
With xSheet
xSheet.Activate
Set xSheet = ActiveSheet
If xSheet.Name <> "Background" Then
FillFormulaAllSheetTables
End If
End With
Next
Application.ScreenUpdating = True
End Sub


HERE IS THE MACRO THAT RUNS ON EACH SHEET

Sub FillFormulaAllSheetTables()
Application.ScreenUpdating = False
Application.EnableEvents = False
Dim xSheet As Worksheet
Dim xTable As ListObject
Dim zCell As Range
Set xSheet = ActiveSheet
For Each xTable In xSheet.ListObjects
With xTable
For Each zCell In xTable.DataBodyRange.Cells
.Formula = "=@cw_mapdesc(" & Chr(34) & zCell.Offset(0, -1 * (zCell.Column - 1)).Value2 & Chr(34) & ")"
Next
End With
Next
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,209
Members
453,022
Latest member
RobertV1609

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