Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

howto add a formula in a Sheet with VB 6.0 1

Status
Not open for further replies.

Gilske

Programmer
Oct 9, 2003
9
BE
Hi everybody

how do you put a formula in a cell with VB 6.0
I tried making a macro and adapting the code but it still won't work

I've got this none-working code


Code:
oSheet1.Cells(TlRow, 9).Select
        ActiveCell.Formula = "=IF(ISNUMBER(G" & TlRow & ");IF(ABS(H" & TlRow & ")>0,3;" * ";"");"")"

I've found this here but it wouldn't work
click here



Can you help me?

 
There's nothing wrong with what you're doing, it's just that your string is not set up properly - that asterisk should probably be an ampersand and some of your semicolons should be commas, but it still doesn't work.

The clearest thing to do would be to set up a string variable and assign your formula to that, then assign the string to the cell's formula like this:

Code:
sMyString = "=IF(ISNUMBER(G" & TlRow & ");IF(ABS(H" & TlRow & ")>0,3;" * ";"");"")"
ActiveCell.Formula = sMyString

That way you'll get a better idea of what's going wrong in the debugger.

N.
 
Note that even if you have local formula names, list and decimal separators in excel, in VBA you use VBA specific: "," for argument separators, "." for decimal separator.

combo
 
Guys
I don't want to offend you but your sollutions wouldn't work
i didn't need to use .Formula but .FormulaLocal.

oSheet1.Cells(TlRij, 9).FormulaLocal = "=IF(ISNUMBER($G" & TlRij & ");IF(ABS($H" & TlRij & ")>0,3;""*"";"""");"""")"

strange but true

Thnx for your help anyway

Koen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top