Need VBA to remove leading apostrophe in the text of a formula to convert the text to the actual formula

jerry12302

Active Member
Joined
Apr 18, 2005
Messages
449
Office Version
  1. 2010
Platform
  1. Windows
I build formulas using concatenation and range value them to create the text of the actual formulas I need in order to build complex link formulas with variable ranges and file names. Below is an example:

'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-01.xlsm]Summary Report'!S21
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-01.xlsm]Summary Report'!S22
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-01.xlsm]Summary Report'!S23
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-01.xlsm]Summary Report'!S24
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-02.xlsm]Summary Report'!S21
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-02.xlsm]Summary Report'!S22
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-02.xlsm]Summary Report'!S23
'=+'C:\MyExcelfiles\Budgets\2021\[Budget 2021-02.xlsm]Summary Report'!S24

Since Excel cannot link to another file using text of the desired file name and range within another cell, like I can do in Lotus with @@(@coord(3,5,100,8)), for example, I would like to remove the preceding apostrophes in the text of the linking formula using VBA. Currently I would have to edit every formula to manually remove it to get the formula I need. I have hundreds of these.

In Lotus a simple macro would be {EDIT}{HOME}{DEL}~ I could never find an Excel equivalent.

Any ideas?
 
Then the only way to get rid of the text format character (single apostrophe) is to use ClearFormats as I mentioned above. I'm referring to the ' you would see in the formula bar at the beginning of the cell contents displayed there but do not see in the actual cell contents. Text to columns won't work because ' is not data, it's a formatting character - invisible, kind of like linefeed characters and such. That makes me wonder how you seem to be getting that character into your output (wherever you're using your data).
 
Upvote 0

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Another alternative:

VBA Code:
Sub Test()
'
    Dim Cel As Range
'
    For Each Cel In Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
        Cel.Value = "=" & Mid(Cel.Value, 2)
    Next
End Sub

That worked Johnny, excellent suggestion, I never used Mid in VBA before. Thanks, this will save a lot of headache.
 
Upvote 0
Then the only way to get rid of the text format character (single apostrophe) is to use ClearFormats as I mentioned above. I'm referring to the ' you would see in the formula bar at the beginning of the cell contents displayed there but do not see in the actual cell contents. Text to columns won't work because ' is not data, it's a formatting character - invisible, kind of like linefeed characters and such. That makes me wonder how you seem to be getting that character into your output (wherever you're using your data).
Thanks, but the clearformats code did not work either. Johnny's answer works great, though. Thanks for the suggestions.
 
Upvote 0
Thanks, but the clearformats code did not work either.
Then I'd say it was not a formatting character - it was actual data.
 
Upvote 0
@jerry12302 you could perhaps try like below

VBA Code:
Sub Test()
Set MyRange = Range("A1:A" & Range("A" & Rows.Count).End(xlUp).Row)
MyRange.Formula = MyRange.Text
End Sub

Unlike Johnny's code that should not return '=" for any blank cells.?
 
Upvote 0

Forum statistics

Threads
1,214,650
Messages
6,120,734
Members
448,987
Latest member
marion_davis

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