Replace Value with Formula

StigPfau

New Member
Joined
May 13, 2014
Messages
3
Hi everybody,

hope anybody can help.

I need a solution for an excel problem:

My sheet hat a lot of absolute values in a row e.g:

5, 3, 7, 6, 4, 4

I need to change this values into formulas like:

= Value (activecell) * value of a cell ($D$5)


My idea was something like that:
Code:
Sub test()
Dim Value As Variant
strFormula = "Value * $D$5"
ActiveCell.Formula = strFormula
End Sub

So the script has to read the active cell, modify the value an wite it in the same cell.

Thanks for you help

Stig
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
Welcome to the Board!

This should be all that you need:
Code:
Sub test()
    ActiveCell.Formula = "=$D$5 * " & ActiveCell.Value
End Sub
 
Upvote 0
The following code would loop through cells and replace the content by its content multiply against D2

Excel Workbook
CD
1CheckAbsolute
23430
356
478
Sheet1

After the code

Excel Workbook
CD
1CheckAbsolute
2102030
31680
42340
Sheet1

Code used

Sub loop12()
Range("c2").Select
Do Until ActiveCell.Value = ""
ActiveCell.Formula = "=" & ActiveCell.Value & "*$D$2"
ActiveCell.Offset(1, 0).Select
Loop
End Sub
 
Upvote 0
Thanks for the great code. Works great.
Onnly one thing: if the fields are signed as cuurency, there is an error.
 
Upvote 0
Only one thing: if the fields are signed as currency, there is an error.
I do not see that with either solution provided.
Are you sure that your entries are numbers formatted as currency, and not text entries?
Because that WOULD cause an error, as the dollar sign would be a literal value in that cell.
 
Upvote 0
Hi,

yes I double checked. The cells are number formatted with decimals.
Any idea - I need to fix the sheet.
 
Upvote 0
Please provide actual data examples you are working with, and post the exact VBA code you are currently using.
 
Upvote 0

Forum statistics

Threads
1,216,743
Messages
6,132,459
Members
449,729
Latest member
davelevnt

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