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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA for excel

Status
Not open for further replies.

chopin33

Programmer
Jun 24, 2002
5
CA
Hi,
I am trying to update the content of a cell by using the code ActiveCell.FormulaR1C1 = formula, in which "formula" is the string "= 2 + median(...values)". However I kept on getting the "Application-defined or object defined" error. What is the reason for this error? I'm new to VBA and any help is greated appreciated. Thanks!

Xian
 
Median isn't a VBA function. However, you can access it through the
Code:
Application.WorksheetFunction
object, ie

Code:
Application.WorksheetFunction.Median(arguments)

All the other functions in Excel can similarly be accessed in this way.

Hope this helps.

SuperBry!
 
Hi, chopin33,

Are you sure that a cell is selected, and not some other object? This works...
Code:
Sub atest()
    ActiveCell.FormulaR1C1 = "=2+ median(2,3,4,5)"
End Sub
Hope this helps :)

Skip,
SkipAndMary1017@mindspring.com
 
...a bit of an "assist" (with tongue firmly in cheek) :)

This also works (i.e. without the "R1C1")

Sub atest()
ActiveCell.Formula = "=2+ median(2,3,4,5)"
End Sub

Welcome back, Skip !!! ;-)

Regards, ...Dale Watson dwatson@bsi.gov.mb.ca
 
the code activeCell.formulaR1C1 = "2 + median(...)" worked fine on its own, but caused errors when I combined it with a bunch of other code. Maybe there's some error in the other part?

Xian
 
Again, you need to look at what object has been selected prior to your statement. Skip,
SkipAndMary1017@mindspring.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top