Problem in setting Excel formula through VB

S

Sathyaish

When I set this formula through VB code,



code:
--------------------------------------------------------------------------------
=((D6*G6)+(E6*1.5*G6)+I6+J6+K6+L6)
--------------------------------------------------------------------------------


for a cell it makes this formula the text of the cell and not the
formula.

Here's my code:


code:
--------------------------------------------------------------------------------
StrFormula = " =((" & GetColumnAlphabet(colRegularHours) &
LngCurrentRow & "*" & GetColumnAlphabet(colPayRate) & LngCurrentRow &
")" & _
"+(" & GetColumnAlphabet(colOvertime) & LngCurrentRow &
"*1.5*" & GetColumnAlphabet(colPayRate) & LngCurrentRow & ")" & _
"+" & GetColumnAlphabet(colSalary) & LngCurrentRow & "+" &
GetColumnAlphabet(colCommission) & LngCurrentRow & _
"+" & GetColumnAlphabet(colBonus) & LngCurrentRow & "+" &
GetColumnAlphabet(colOther) & LngCurrentRow & ")"
Debug.Print StrFormula
Range(GetColumnAlphabet(colGrossTotal) &
LngCurrentRow).Formula = StrFormula
 
B

Bob Phillips

Make sure that the target cells are formatted as General and not Text.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
K

kkknie

The only way I could duplicate it was if the cell was formatted as text
If you add

Range(GetColumnAlphabet(colGrossTotal) & LngCurrentRow).NumberFormat
"General"

just before setting the formula, it should work.
 
D

Dave Peterson

Watch out for the leading spaces!

StrFormula = " =((" & .....

StrFormula = "=((" & .....
 

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