ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Select range -- convert formulas to values (https://www.excelbanter.com/excel-programming/332400-select-range-convert-formulas-values.html)

Johnny[_9_]

Select range -- convert formulas to values
 
I understand how to convert a formula to a value:
Range("A1").Formula = Range("A1").Value

Can somebody help with the syntax to use the selected range instead of
hard-coding a range into the macro?


JPW

Select range -- convert formulas to values
 
Public Sub SelectionFormToVal()

Dim tCell as Range

If TypeName(Selection) < "Range" Then Exit Sub

For Each tCell in Selection
tCell.Formula = tCell.Value
Next tCell



"Johnny" wrote in message
oups.com...
I understand how to convert a formula to a value:
Range("A1").Formula = Range("A1").Value

Can somebody help with the syntax to use the selected range instead of
hard-coding a range into the macro?




Gary's Student

Select range -- convert formulas to values
 
The following will convert formulae to values in the range you select:

Sub freeze_it()
Selection.Value = Selection.Value
End Sub

There is probably no reason to test the individual cells in the range to see
if they contain data or formula.
--
Gary's Student


"JPW" wrote:

Public Sub SelectionFormToVal()

Dim tCell as Range

If TypeName(Selection) < "Range" Then Exit Sub

For Each tCell in Selection
tCell.Formula = tCell.Value
Next tCell



"Johnny" wrote in message
oups.com...
I understand how to convert a formula to a value:
Range("A1").Formula = Range("A1").Value

Can somebody help with the syntax to use the selected range instead of
hard-coding a range into the macro?





dominicb[_35_]

Select range -- convert formulas to values
 

Good afternoon Johnny

There are a few ways of doing this. Try this:

Selection.Formula = Selection.Value

or this will also do the trick:

For Each UsrCell In Selection
UsrCell.Formula = UsrCell.Value
Next UsrCell

HTH

DominicB


--
dominicb
------------------------------------------------------------------------
dominicb's Profile: http://www.excelforum.com/member.php...o&userid=18932
View this thread: http://www.excelforum.com/showthread...hreadid=380876



All times are GMT +1. The time now is 02:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com