![]() |
Problem in setting Excel formula through VB
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 -------------------------------------------------------------------------------- What could be the problem? |
Problem in setting Excel formula through VB
Hi
have you checked the cell is not formated as 'Text'? -- Regards Frank Kabel Frankfurt, Germany Sathyaish wrote: 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 --------------------------------------------------------------------- ----------- What could be the problem? |
Problem in setting Excel formula through VB
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) "Sathyaish" wrote in message m... 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 -------------------------------------------------------------------------- ------ What could be the problem? |
Problem in setting Excel formula through VB
Dave Peterson ) said: Watch out for the leading spaces!
Sathyaish replies: Dave, you're the man! Thanks so much. Regards, Sathyaish Chakravarthy. |
All times are GMT +1. The time now is 09:59 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com