ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Macro To Change a Formula to A Value (https://www.excelbanter.com/excel-worksheet-functions/114242-macro-change-formula-value.html)

Carl

Macro To Change a Formula to A Value
 
I have a formula in ColB of my worksheet.

The value of the formula will be zero or a positive number.

Is it possible for a macro to change the formula to its value if the value
is not equal to zero ?

Thank you in advance.

Stefi

Macro To Change a Formula to A Value
 
Sub changetoval()
Range("B2:B8").Select 'ADJUST RANGE!
For Each cella In Selection
If cella < 0 Then
cella.Value = cella
End If
Next cella
End Sub

Regards,
Stefi


€˛carl€¯ ezt Ć*rta:

I have a formula in ColB of my worksheet.

The value of the formula will be zero or a positive number.

Is it possible for a macro to change the formula to its value if the value
is not equal to zero ?

Thank you in advance.


Bob Phillips

Macro To Change a Formula to A Value
 
Stefi,

No need to do wasteful selecting

Sub changetoval()
For Each cella In Range("B2:B8") 'ADJUST RANGE!
If cella < 0 Then
cella.Value = cella.Value
End If
Next cella
End Sub


--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Stefi" wrote in message
...
Sub changetoval()
Range("B2:B8").Select 'ADJUST RANGE!
For Each cella In Selection
If cella < 0 Then
cella.Value = cella
End If
Next cella
End Sub

Regards,
Stefi


"carl" ezt ķrta:

I have a formula in ColB of my worksheet.

The value of the formula will be zero or a positive number.

Is it possible for a macro to change the formula to its value if the

value
is not equal to zero ?

Thank you in advance.





All times are GMT +1. The time now is 10:52 AM.

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