Consulting

Results 1 to 3 of 3

Thread: working with ranges in custom function

  1. #1
    VBAX Regular
    Joined
    Dec 2008
    Posts
    13
    Location

    working with ranges in custom function

    Hi All
    I posted the following on Mr Excel.com

    http://www.mrexcel.com/forum/excel-q...lications.html

    It is currently unanswered and I think as its a vba question, this would have been the better forum to post it in.

    If anybody can help please post a response there.

    Thanks Dgs2001

  2. #2
    VBAX Regular
    Joined
    Dec 2008
    Posts
    13
    Location

    Solved : working with ranges in custom function

    Ok I think I solved this.

    I forgot the basics again !

    my column of data had some text so I needed a basic Isnumeric check.


    Although solved I am open to suggestions to a better or more efficient code.

    Thanks
    Last edited by dgs2001; 04-18-2013 at 02:39 AM.

  3. #3
    VBAX Sage SamT's Avatar
    Joined
    Oct 2006
    Location
    Near Columbia
    Posts
    7,814
    Location
    So you expect me to sign up for another forum to see your code?

    Any way, Rank ignores Text.

    You've declared v2 as a Variant, then forced VBA to guess what you want when you assign a range to it.

    For Each r3 In r2.Columns(21)
        rnk = WorksheetFunction.Rank(r3, r2.Columns(21), 0)
    Have you considered what will happen if you have two cells ranked #1?

    Rank1 will be set to the second cell ranked #1 and there will be no cell ranked #2.


    Function getSel(r2 As Range) As String
    Dim v2 As Variant, r3 As Range, r4 As Range
    Dim rank1 As Range, rank2 As Range, rnk As Integer
    Set v2 = r2.Columns(21)
    For Each r3 In v2
       rnk = WorksheetFunction.Rank(r3, v2, 0)
       If rnk = 1 Then Set rank1 = r3
       If rnk = 2 Then Set rank2 = r3
            Next
    ''' other stuff see below '''
    End Function
    Last edited by Aussiebear; 03-26-2023 at 01:12 AM. Reason: Adjusted code tags
    I expect the student to do their homework and find all the errrors I leeve in.


    Please take the time to read the Forum FAQ

Posting Permissions

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