Get formatted value/text of a Range without looping

tttmack

New Member
Joined
Dec 17, 2014
Messages
16
I'd like to be able to efficiently read all of the formatted values of a range of cells into an array. When I say formatted values, I mean the values as they are shown on the screen.

Range.Value and Range.Value2 can efficiently retrieve the values into an array.

Range.Text seems to work only on a single cell at a time and additionally the column needs to be autofitted first or you may get something like #### if the column is too small to display everything.

The problem with Range.Text is that it involves looping and while it is slow in VBA, it is extremely slow in VSTO.

Is there any other way that I can retrieve the text as it appears on screen efficiently using some other property or trick?

Note that Range.NumberFormat also doesn't work for multiple cells unless they all have the same NumberFormat. So a solution of using NumberFormat along side Value or Value2 is not feasible either since NumberFormat would involve looping.
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Will this work for you?

Code:
'Careful - loss of accuracy is permanent
ActiveWorkbook.PrecisionAsDisplayed = True
vFormattedData = rngMyRange.Value
 
Upvote 0
thanks but PrecisionAsDisplayed wont work. For example a value of 0.1234 with NumberFormat = "0.0%" has a .Text property of "12.3%". After calling PrecisionAsDisplayed = True, the .Value property is 0.123, but in order to make it look like 12.3% you would still need to either use .Text or .Value & .NumberFormat
 
Upvote 0

Forum statistics

Threads
1,214,575
Messages
6,120,334
Members
448,956
Latest member
Adamsxl

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