Use a result variable for a formula using VBA

alejandro1404

New Member
Joined
Feb 10, 2016
Messages
2
Hi all,

I'm new in forums, so I apologize if I do something wrong.

I have a question about using VBA for setting a formula. I have to do this:
1-Save a result from a formula in the file "Macro" in a variable called "var"
2-In the file "model" save the formula in a variable called "pivote"
3-Set a new formula as 'Pivote & "*" & var' in a cell in the file "model departamento"

For example:
1- The result is (var=)0,015
2- The formula is (pivote=)"=4000*20"
3- The formula I want to set is "=4000*20*0.015"

The problem I have in here is that there is an error, because (I think) the result of 'var' uses a 'comma' as a decimal and Excel uses a 'dot'. So when I run this code there shows the error 1004.

I really appreciate your help. Here is the code I'using:

PD: If you know a better code or a better way to do it, please tell me.

Thanks a lot
alejandro1404

Code:
Windows("macro.xlsx").Activate
var = Range(Cells(cont_dep, 28), Cells(cont_dep, 28)).Value


Windows("model.xlsx").Activate
Pivote = Range(Cells(119, 6), Cells(119, 6)).Formula


Windows("model " & departamento & ".xlsx").Activate
Range(Cells(119, 6), Cells(119, 6)).Select
ActiveCell.Formula = Pivote & "*" & var
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
Thanks Thanks Thanks a lot!!!!!!!!!!!!!!!!!!!!
It worked perfectly
Do you know why this incompatibility?? I mean, Why taking a result from Excel to use it in Excel again generates this kind of error?
 
Upvote 0

Forum statistics

Threads
1,217,349
Messages
6,136,051
Members
449,985
Latest member
rittersportyummy

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