Can someone tell me if there is a function that returns a cell’s formula as text?
Ex. BN1789 contains “=-BN1612” and shows “(109.02)”
I know how to copy and paste special values – Values to get the (109.02) into a new cell,
and I know how to copy and paste special values – Formulas to get the formula itself into a new cell… but this displays the value referred to…
I want to see “-BN1612” in the new cell…
Is this possible??
![]() |
Patch reliability is unclear. Unless you have an immediate, pressing need to install a specific patch, don't do it. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Copying formula as text (2000 SR-1)
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » Copying formula as text (2000 SR-1)
- This topic has 14 replies, 5 voices, and was last updated 21 years, 5 months ago.
AuthorTopicWSAlexya1
AskWoody LoungerOctober 8, 2003 at 6:56 pm #394755Viewing 3 reply threadsAuthorReplies-
WSsdckapr
AskWoody LoungerOctober 8, 2003 at 7:16 pm #726158None built-in, but you can create one easily enough. If you add this to a VB module:
Function DisplayFormula(rng As Range) As String DisplayFormula = rng.Cells(1).Formula End Function
and then enter into a cell:
=DisplayFormula(BN1789)
you should get what you want.
The only other way, I can think of off-hand, is to edit the cell BN1789 add an apostrophe in front of the equal sign, copy it to where you want the formula to display, then re-edit BN1789 to remove the apostrophe.
Steve
-
WSAlexya1
AskWoody LoungerOctober 8, 2003 at 7:26 pm #726162That’s perfect Steve!!
I had used CStr() in a procedure before (thinking that when it went into the new cell it might think it was still a formula…) and that had worked….
Ex. originSheet.Cells(rwNew, 2).Value = CStr(cdnSheet.Cells(rw, col – 3).Formula)
but your function is great for doing this on the fly…I just wanted to know if there was some built in function that would do this that I didn’t know about… There are tons that I don’t know about!!
Thanks a million!
-
WSAlexya1
AskWoody LoungerOctober 8, 2003 at 7:26 pm #726163That’s perfect Steve!!
I had used CStr() in a procedure before (thinking that when it went into the new cell it might think it was still a formula…) and that had worked….
Ex. originSheet.Cells(rwNew, 2).Value = CStr(cdnSheet.Cells(rw, col – 3).Formula)
but your function is great for doing this on the fly…I just wanted to know if there was some built in function that would do this that I didn’t know about… There are tons that I don’t know about!!
Thanks a million!
-
WSsdckapr
AskWoody LoungerOctober 8, 2003 at 7:16 pm #726159None built-in, but you can create one easily enough. If you add this to a VB module:
Function DisplayFormula(rng As Range) As String DisplayFormula = rng.Cells(1).Formula End Function
and then enter into a cell:
=DisplayFormula(BN1789)
you should get what you want.
The only other way, I can think of off-hand, is to edit the cell BN1789 add an apostrophe in front of the equal sign, copy it to where you want the formula to display, then re-edit BN1789 to remove the apostrophe.
Steve
WSWassim
AskWoody LoungerOctober 8, 2003 at 11:42 pm #726313Trudi
Although the answers you got are perfect, but one needs to ask why and what really are you trying to do. If for example you need to make sure that all the formulas are correct, pointing to the right cells/ranges, or have the right elements, in your case it needs a negative number, and things like that, you can go into your Tools Menu and under Options, choose the View tab and select Formulas under Window Options… Mind you this is a worksheet level option, so you will need to do the same for all worksheets conserned.
This will turn all the formulas on and you can inspect them in their cells.
Alternativly, you can change the ‘=’ sign to some unique string, I use ZZZxxxZZZ, or even eliminate it totally, and that will convert the formula into a string. You see Excel knows it a formula by the presence of the equal sign in the begining.
Hope this helps.
Wassim
-
WSAlexya1
AskWoody LoungerOctober 9, 2003 at 12:57 pm #726606Thanks Wassim…
I can understand your curiosity about my intention for this… The thing is that this workbook was created yearsssss ago… and there have been many people making many changes through the years (Not developers either!… )…The workbook is what my company calls the DIR (Daily Interest Report)… The company I work for is a corporate brokerage so all of our inventory is financial products… The workbook is supposed to balance and allocate all interest bearing products by revenue and expense…
There are over 20 sheets and over 1800 named ranges… The sheet has all kinds of tables in funny places… I go bug-eyed trying to figure this thing out…
The previous allocations were done by inventory (account number)… My boss asked me to change the allocations to split by Dept and Product…. I managed to do that quite quickly with a few normalized tables and a few queries in Access… but then the boss said… “Now all of the numbers have to be tied in to the old way”… Apparently there are 4 entries to be booked for each… 2 will be the old way and 2 the new way… Anyway… I’ve already found sooooo many errors… I was trying to figure out where all these numbers were coming from and going to on the sheets and I decided I needed to see the values and the formulas (references) to be able to follow it back… I thought this would be the quickest way…
I appreciate the new information!… I didn’t know that option in the Tools menu… I am by no means an Excel expert… I’m a Programmer Analyst… I’m a Database Developer… lol… It goes against my nature to leave this mess as is… I’d so love to scap this spreadsheet and do it right… BUT it’s close to year end and there’s just no chance I can do it now…
My co-workers (and boss) must hear me say “I HATE this spreadsheet!” 10 times a day at least…
-
WSErrolv
AskWoody LoungerOctober 10, 2003 at 2:05 am #726990A shortcut to see all the formulas is to use [Ctrl] ` (grave accent) (That’s the key usually to the left of the “1” key, and has the two marks ` and ~.) This key combination automatically switches to formula view – and back. The best thing about this is you don’t have to take your eyes off the cell in question.
Also, I rebuilt a 15 page spreadsheet from scratch once to clear up some of the problems you mention. Is that a possibility for you? (You could mumble some buzz words like “efficiency” and “smaller file size” in your boss’s hearing.)
Errol
-
WSAlexya1
AskWoody LoungerOctober 10, 2003 at 11:48 am #727108Thanks Errolv! I love learning new shortcuts like that… I’m sure I’ll use it…
As for rebuilding it… I’ve already spoken to my boss about it… She’s onboard with doing it but says we have to wait until the new business year… There’s an incredible amount of work to be done before the end of October…
This thing is insane… There are text files imported into and stripped in an Access database in the morning… Then there’s another database that imports the data to do with this particular process every day… Then the database does its work and exports 8 tables as spreadsheets… Then someone actually manually copies and pastes the data from each of those .xls files into 8 separate sheets in this workbook… The data is used throughout this workbook but the main purpose (as I’ve now identified) is to create another table on yet another sheet, and export it to yet another Access database to use to print journals (reports) for booking… It blows my mind at how incredibly ridiculous this thing is…
I’ve talked to my boss about it and she understands that it’s not a good way to do things… She says the reason it ended up this way is because different people have created different parts of the thing as needed… This is a perfect example why process we need to analyse the entire department’s processes and do some serious normalizing… I am the first developer that she’s ever hired for the department… It’s always been non technical people creating this stuff…
I think I’m going to have my work cut out for me here but I’m not complaining… I love a challenge!!
-
macropod
AskWoody_MVPOctober 12, 2003 at 9:25 am #727741Hi Trudi,
As an alternative to copying the formulae as text, you might like to convert them to comments attached to the cells themselves. Then, you’ll be able to see each cell’s formula anytime the mouse hovers over it, or by turnimg on the ‘Comment & Indicator’ option in Tools|Options|View.
The following macro adds the formulae to the comments for each selected cell, or even the whole worksheet, and displays the comments in an appropriately-sized box. You may need to adjust the parameters for positioning the comments next to their cells – which only makes a difference when the ‘Comment & Indicator’ option in Tools|Options|View is checked.
Cheers
Sub AddFormulasToComments()
Application.ScreenUpdating = False
‘skip over errors caused by trying to delete comments in cells with no comments
On Error Resume Next
‘If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
‘If the cell contains a formula, turn it into a comment.
For Each TargetCell In CommentRange
With TargetCell
‘check whether the cell has a formula
If Left(.Formula, 1) = “=” Then
‘delete any existing comment
.Comment.Delete
‘add a new comment
.AddComment
‘copy the formula into the comment box
Comment.Text Text:=.Formula
With .Comment.Shape
‘automatically resizes the comment
.TextFrame.AutoSize = True
‘position the comment adjacent to its cell
.IncrementLeft -11.25
.IncrementTop 8.25
End With
End If
End With
Next
Application.ScreenUpdating = True
End SubCheers,
Paul Edstein
[Fmr MS MVP - Word] -
macropod
AskWoody_MVPOctober 12, 2003 at 9:25 am #727742Hi Trudi,
As an alternative to copying the formulae as text, you might like to convert them to comments attached to the cells themselves. Then, you’ll be able to see each cell’s formula anytime the mouse hovers over it, or by turnimg on the ‘Comment & Indicator’ option in Tools|Options|View.
The following macro adds the formulae to the comments for each selected cell, or even the whole worksheet, and displays the comments in an appropriately-sized box. You may need to adjust the parameters for positioning the comments next to their cells – which only makes a difference when the ‘Comment & Indicator’ option in Tools|Options|View is checked.
Cheers
Sub AddFormulasToComments()
Application.ScreenUpdating = False
‘skip over errors caused by trying to delete comments in cells with no comments
On Error Resume Next
‘If the whole worksheet is selected, limit action to the used range.
If Selection.Address = Cells.Address Then
Set CommentRange = Range(ActiveSheet.UsedRange.Address)
Else
Set CommentRange = Range(Selection.Address)
End If
‘If the cell contains a formula, turn it into a comment.
For Each TargetCell In CommentRange
With TargetCell
‘check whether the cell has a formula
If Left(.Formula, 1) = “=” Then
‘delete any existing comment
.Comment.Delete
‘add a new comment
.AddComment
‘copy the formula into the comment box
Comment.Text Text:=.Formula
With .Comment.Shape
‘automatically resizes the comment
.TextFrame.AutoSize = True
‘position the comment adjacent to its cell
.IncrementLeft -11.25
.IncrementTop 8.25
End With
End If
End With
Next
Application.ScreenUpdating = True
End SubCheers,
Paul Edstein
[Fmr MS MVP - Word]
-
-
-
WSAlexya1
AskWoody LoungerOctober 10, 2003 at 11:48 am #727109Thanks Errolv! I love learning new shortcuts like that… I’m sure I’ll use it…
As for rebuilding it… I’ve already spoken to my boss about it… She’s onboard with doing it but says we have to wait until the new business year… There’s an incredible amount of work to be done before the end of October…
This thing is insane… There are text files imported into and stripped in an Access database in the morning… Then there’s another database that imports the data to do with this particular process every day… Then the database does its work and exports 8 tables as spreadsheets… Then someone actually manually copies and pastes the data from each of those .xls files into 8 separate sheets in this workbook… The data is used throughout this workbook but the main purpose (as I’ve now identified) is to create another table on yet another sheet, and export it to yet another Access database to use to print journals (reports) for booking… It blows my mind at how incredibly ridiculous this thing is…
I’ve talked to my boss about it and she understands that it’s not a good way to do things… She says the reason it ended up this way is because different people have created different parts of the thing as needed… This is a perfect example why process we need to analyse the entire department’s processes and do some serious normalizing… I am the first developer that she’s ever hired for the department… It’s always been non technical people creating this stuff…
I think I’m going to have my work cut out for me here but I’m not complaining… I love a challenge!!
-
WSErrolv
AskWoody LoungerOctober 10, 2003 at 2:05 am #726991A shortcut to see all the formulas is to use [Ctrl] ` (grave accent) (That’s the key usually to the left of the “1” key, and has the two marks ` and ~.) This key combination automatically switches to formula view – and back. The best thing about this is you don’t have to take your eyes off the cell in question.
Also, I rebuilt a 15 page spreadsheet from scratch once to clear up some of the problems you mention. Is that a possibility for you? (You could mumble some buzz words like “efficiency” and “smaller file size” in your boss’s hearing.)
Errol
WSAlexya1
AskWoody LoungerOctober 9, 2003 at 12:57 pm #726607Thanks Wassim…
I can understand your curiosity about my intention for this… The thing is that this workbook was created yearsssss ago… and there have been many people making many changes through the years (Not developers either!… )…The workbook is what my company calls the DIR (Daily Interest Report)… The company I work for is a corporate brokerage so all of our inventory is financial products… The workbook is supposed to balance and allocate all interest bearing products by revenue and expense…
There are over 20 sheets and over 1800 named ranges… The sheet has all kinds of tables in funny places… I go bug-eyed trying to figure this thing out…
The previous allocations were done by inventory (account number)… My boss asked me to change the allocations to split by Dept and Product…. I managed to do that quite quickly with a few normalized tables and a few queries in Access… but then the boss said… “Now all of the numbers have to be tied in to the old way”… Apparently there are 4 entries to be booked for each… 2 will be the old way and 2 the new way… Anyway… I’ve already found sooooo many errors… I was trying to figure out where all these numbers were coming from and going to on the sheets and I decided I needed to see the values and the formulas (references) to be able to follow it back… I thought this would be the quickest way…
I appreciate the new information!… I didn’t know that option in the Tools menu… I am by no means an Excel expert… I’m a Programmer Analyst… I’m a Database Developer… lol… It goes against my nature to leave this mess as is… I’d so love to scap this spreadsheet and do it right… BUT it’s close to year end and there’s just no chance I can do it now…
My co-workers (and boss) must hear me say “I HATE this spreadsheet!” 10 times a day at least…
WSWassim
AskWoody LoungerOctober 8, 2003 at 11:42 pm #726314Trudi
Although the answers you got are perfect, but one needs to ask why and what really are you trying to do. If for example you need to make sure that all the formulas are correct, pointing to the right cells/ranges, or have the right elements, in your case it needs a negative number, and things like that, you can go into your Tools Menu and under Options, choose the View tab and select Formulas under Window Options… Mind you this is a worksheet level option, so you will need to do the same for all worksheets conserned.
This will turn all the formulas on and you can inspect them in their cells.
Alternativly, you can change the ‘=’ sign to some unique string, I use ZZZxxxZZZ, or even eliminate it totally, and that will convert the formula into a string. You see Excel knows it a formula by the presence of the equal sign in the begining.
Hope this helps.
Wassim
Viewing 3 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
Looking for Microsoft Defender Manuals/Tutorial
by
blueboy714
1 hour, 35 minutes ago -
Win 11 24H2 Home or Pro?
by
CWBillow
32 minutes ago -
Bipartisan Effort to Sunset the ‘26 Words That Created the Internet’..
by
Alex5723
10 hours, 1 minute ago -
Outlook new and edge do not load
by
cHJARLES a pECKHAM
21 hours, 57 minutes ago -
Problem using exfat drives for backup
by
Danmc
22 hours, 15 minutes ago -
I hate that AI is on every computer we have!
by
1bumthumb
15 minutes ago -
Change Info in the Settings window
by
CWBillow
1 day, 4 hours ago -
Attestation readiness verifier for TPM reliability
by
Alex5723
1 day, 11 hours ago -
Windows Update says that “some settings are managed b your organization”
by
Ed Willers
21 hours, 4 minutes ago -
Use of Gmail rejected.
by
CBFPD-Chief115
21 hours, 44 minutes ago -
WuMgr operational questions
by
Tex265
1 hour, 14 minutes ago -
Beijing’s unprecedented half-marathon: Humans vs. humanoids!
by
Alex5723
2 days, 2 hours ago -
New Phishing Campaign Targeted at Mac Users
by
Alex5723
1 day, 3 hours ago -
Backing up Google Calendar
by
CWBillow
2 days, 9 hours ago -
Windows 11 Insider Preview build 27818 released to Canary
by
joep517
2 days, 21 hours ago -
File Naming Conventions (including Folders)
by
Magic66
1 day, 20 hours ago -
Windows 11 Insider Preview Build 26100.3613 (24H2) released to Release Preview
by
joep517
3 days, 5 hours ago -
Microsoft sends emails to Windows 10 users about EOS
by
Alex5723
2 days, 15 hours ago -
Outlook 2024 importing Calendar and Contacts – FAILURE
by
Kathy Stevens
1 day, 22 hours ago -
Adding Microsoft Account.
by
DaveBRenn
3 days, 6 hours ago -
Windows 11 Insider Preview build 26120.3576 released to DEV and BETA
by
joep517
4 days, 6 hours ago -
Windows 11 Insider Preview Build 22635.5090 (23H2) released to BETA
by
joep517
4 days, 6 hours ago -
Windows 11 won’t boot
by
goducks25
1 day, 22 hours ago -
Choosing virtual machine product for Windows on Mac
by
peterb
3 days, 20 hours ago -
Rest in Peace
by
Roy Lasris
5 days ago -
CISA : Install Windows March 2025 Updates until April 1 or shut down PC.
by
Alex5723
1 day, 22 hours ago -
Google proposes users with incompatible Win 11 PCs to migrate to ChromeOS Flex
by
Alex5723
5 days, 1 hour ago -
Drivers for Epson Perfection V600 Photo – scanner
by
Bookman
1 day, 16 hours ago -
Long Time Member
by
jackpet
5 days, 3 hours ago -
Woody Leonhard (1951–2025)
by
Will Fastie
3 hours, 12 minutes ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.