use a macro to insert formulas in a cell

AnnetteTR

Board Regular
Joined
Aug 19, 2010
Messages
85
Hello
I'm about to make a macro where the user enters a lot of data for some rooms in an input box. These data are passed in one line in a spreadsheet. Next room input inserted in the next line, etc.
The problem is that in some columns/cells , I want to put a formula which is based on some of the other inputs. But how should the formula look like in VBA?
I have my input box, where I have a "Sub" for what happens when I press the Save button
Next available number is activated and data is stored with an offset:
With ActiveSync cell
. Offset (0, 22). Value = txtSS1.Text
. Offset (0, 23). Value = txtSS1br.Text
. Offset (0, 24). Value = txtLugeEtMin
. Offset (0, 25). Value = txtLugeEtMax

I want to create a formula where the cell reference for SS1br and LugeEtMin included

I expect to put the formula in with this feature:
'. Offset (0 , 26). Formula = SS1br * LugeEtMin * 0.3 * 3.6<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:eek:ffice:eek:ffice" /><o:p></o:p>
But I want the formula to be put in cell .Offset (0 , 26) not the value<o:p></o:p>
What should be in the cell is an equation something like: = X4 * Z4 * 0.3 * 3.6
where the 4-figure must be the current row<o:p></o:p>


How should the formula look like?

Regards Annette
<o:p></o:p>
 
I'm glad it worked for you. If you turn on the macro recorder and enter the formula (or F2 Enter if it's already there) you will get the syntax.
 
Upvote 0

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.

Forum statistics

Threads
1,215,465
Messages
6,124,977
Members
449,200
Latest member
Jamil ahmed

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