What's the proper way to get another cell's display text in VBA?

ivorhorton

New Member
Joined
Jan 18, 2019
Messages
7
For a number 42117, it can be displayed as 42117, or 23-Apr-15, or 42,117.00 etc. I want to reference these displayed text appearance in another cell through VBA. How can I get it? I have below customized function and it uses the Text property. It still not work properly and hope someone can point me the right direction. Thanks in advance.

Code:
Public Function DisplayText(r As Range)
    DisplayText = r.Text
End Function
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
How does it not work properly? The UDF looks fine.
I would add a declaration that the function return a string and to return the top left cell of r.
 
Upvote 0
Yes, that will make the function more robust. But for now, since the range always has a single cell, I'll not improve it at the moment.

I said it doesn't work properly, is because I did some test. It works for the first time. Later when I changed the source's display, the destination doesn't change accordingly. I pressed F9 to recalculate and it doesn't work. A few minutes ago I just found I have to double click the destination cell and make it in the formula editing mode, then I press ctrl + enter it will recalculate behave as I expected. How can I solve this issue?
 
Upvote 0
This will help
Code:
Public Function DisplayText(r As Range)
   Application.Volatile
   DisplayText = r.Text
End Function
but you will still need to press F9, as changing the format will not trigger the function.
 
Upvote 0

Forum statistics

Threads
1,223,894
Messages
6,175,254
Members
452,624
Latest member
gregg777

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