Macro

G

Gustavo Strabeli

Hi there!

Can anyone please inform how I can built a macro to apply a formula to some cells?
In other words, I need a button to click on it and have below formula applied from cell M13 until the last data in the same column M.
Formula is: =IF(OR(L13="40HC";L13="40RH");K13*2,25;IF(LEFT(L13;2)="40";K13*2;K13))

Thanks a lot.
Gustavo.
 
G

Guest

set rng = Range("L13",Range("L13").End(xldown)).offset(0,1)
rng.formula =
"=IF(OR(L13=""40HC"",L13=""40RH""),K13*2,25,IF(LEFT(L13,2)=""40"",K13*2,K13))"
 
G

Gustavo Strabeli

Tom,

It's almost OK despite the fact that when I click on the button all the results in column M are #NAME?
However, if I click on the formula bar, the result appears...
Any idea?

Tks.


"Tom Ogilvy" <[email protected]> escreveu na mensagem set rng = Range("L13",Range("L13").End(xldown)).offset(0,1)
rng.formula =
"=IF(OR(L13=""40HC"",L13=""40RH""),K13*2,25,IF(LEFT(L13,2)=""40"",K13*2,K13))"
 
G

Gustavo Strabeli

They're set as automatic.
It's strange because when I put the cursor in the formula bar, the result appears, but I have to do it cell by cell.


"steve_doc" <[email protected]> escreveu na mensagem Tools/Options/Calculations
are your calculation setting set to manual/Automatic?
 
G

Guest

"=IF(OR(L13=""40HC"",L13=""40RH""),K13*2,25,IF(LEFT(L13,2)=""40"",K13*2,K13))"

should have the comma in 2,25 changed to a period 2.25

I don't know if that will help.
 
G

Gustavo Strabeli

Tried it already, but without sucess...
By chance do you know what the cause would be?


"Tom Ogilvy" <[email protected]> escreveu na mensagem "=IF(OR(L13=""40HC"",L13=""40RH""),K13*2,25,IF(LEFT(L13,2)=""40"",K13*2,K13))"

should have the comma in 2,25 changed to a period 2.25

I don't know if that will help.
 
G

Gustavo Strabeli

Tom,
I made it!
My excel is in Portuguese and I was inserting the function "IF(OR...." in Portuguese, but as one last trial, I changed it to English and it worked!
Thanks a lot for your help.

Gustavo.

"Gustavo Strabeli" <[email protected]> escreveu na mensagem Tried it already, but without sucess...
By chance do you know what the cause would be?


"Tom Ogilvy" <[email protected]> escreveu na mensagem "=IF(OR(L13=""40HC"",L13=""40RH""),K13*2,25,IF(LEFT(L13,2)=""40"",K13*2,K13))"

should have the comma in 2,25 changed to a period 2.25

I don't know if that will help.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top