Consulting

Results 1 to 8 of 8

Thread: how to use vara function in vba

  1. #1

    how to use vara function in vba

    hello
    I am a begginer in vba but I think I got the hang of it, in my lab we are using windows 2000, excel form 2002...

    I dont understand why this code:

    [vba]Sub t()
    Range("c1").Value = Application.Vara(Range("a1:a5"))
    End Sub[/VBA]

    doesnt work. where, this code:

    [VBA]Sub t()
    Range("c1").Value = Application.Var(Range("a1:a5"))
    End Sub
    [/vba] does work. after all vara is just another statistical function supplied by excel.
    the error message is 438 - doens't know the method. but I can use it on excel sheets

    thank you very much for whom ever tries to help

    Arielon

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try
    [vba]Range("C1").Value = Evaluate("=vara(A1:A5)")

    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    thank you very much

    but I am looking for a solution that would allow me to use range that is a variable for example:

    [VBA]Dim r As Range
    Set r = Range("a1:a5")
    Range("c1").Value = Application.Vara(Range(r))[/VBA]

    this ofcourse doesn't work...

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    [vba]Sub GetVara()
    Dim r As Range
    Set r = Range("a1:a5")
    Range("c1").Value = Evaluate("=VARA(" & r.Address & ")")
    End Sub
    [/vba]

    You could also use a sub to write the required VARA function into a cell
    [vba]
    Sub GetVara2()
    Dim r As Range
    Set r = Range("a1:a5")
    Range("C2").Formula = "=VARA(" & r.Address & ")"
    End Sub
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    hi, and again thanks

    is there a more direct way to use the vara method?
    why is it different from using the var method?

    thanks

  6. #6
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    How more direct do you want?

    It is that way because MS in their wisdom have not exposed VARA as a worksheet function, just as they have failed to expose MAXA.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  7. #7
    thanks
    I was not aware to that issue I was sure that every method in excel is use-able in vba...

  8. #8
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Every function is, it just might be that you need a different approach.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •