+ Reply to Thread
Results 1 to 13 of 13

object defined error

Hybrid View

  1. #1
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    object defined error

    What is wrong with the statement below

    Selection.Offset(0, 1).Value = "=Rank(Selection.Value, ""(Selection.cell)"" & "":"" & ""(Selection.Offset(x, 0))"")"
    x is the range of cells that have values in them.

    thanks

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    This is what you are putting in the cell.
    Formula: copy to clipboard

    =Rank(Selection.Value, "(Selection.cell)" & ":" & "(Selection.Offset(x, 0))")

    That's not a valid formula, that's why you get the error.

    What formula are you actually trying to put in the cell?
    If posting code please use code tags, see here.

  3. #3
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    i am using this in VBA I just dont know how to use the rank function without actual cell names. Instead of RANK(A1,A1:A10,0) I want Rank(selection.value,(selected cell)selected cell+5),0)

    or having 5 as a symbol that signifies how many cells have values in them

  4. #4
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    Try this.
    Selection.Offset(0,1).Formula = "=RANK(" & Selection.Value & "," & Selection.Resize(5).Address & ", 0)"

  5. #5
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    something like this:

    a = 0
            Do Until Selection.Offset(a, 0) = ""
            Selection.Offset(a, 1).Formula = "=RANK(" & Selection.Offset(a, 0).Value & "," & Selection.Resize(x).Address & ", 0)"
            a = a + 1
            Loop

  6. #6
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    that works great for a single element, what would i change if i had it in a loop so im still looking at the same range but the second element?

  7. #7
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    I don't think that will work.

    What range do you want to put the formula in and what's the actual formula?

  8. #8
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    x = 0
            Do Until Selection.Value = ""
            Selection.Offset(1, 0).Select
            x = x + 1
            Loop
            a = 0
            Selection.Offset(-x, 0).Select
            Do Until Selection.Value = ""
            Selection.Offset(0, 1).Formula = "=RANK(" & Selection.Value & "," & Selection.Resize(5).Address & ", 0)"
            a = a + 1
            Selection.Offset(1,0).Select
            Loop
    the range is the value of x as it could change and the formula is the one you gave me, it just doesn't work in a do loop for obvious reasons.

    Thanks for your help

  9. #9
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    Can you tell us what range you want to put the formula in?

    Also, what is the formula as it would look like on a worksheet?

    One thing you really need to get rid of is all that Select and Selection.

    It's not needed and can actually make things harder.

  10. #10
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    ok, the range starts in cell B11 and depending on how many projects are entered depends on how far down it goes. I am not sure what the formula would look like on a worksheet because I am not sure how i would enter it if I don't know the actual range. It would be something between

    RANK(B11,$B$11:$B$12,0) and RANK(B11,$B$11:$B$36,0)

    and then I would drag it down the column.

    I can do it manually in the worksheet doing just what i said above but I am making this for someone so all he has to do is hit a button.

    Thanks again

  11. #11
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    Is the 2nd argument actually the same on each row, but can change depending on the no of projects?

    Try this.
    LastRow = Range("B" & Rows.Count).End(xlUp).Row
    
    Range("C11:C" & LastRow).Formula = "=RANK(B11, $B$11:$B$" & LastRow & ", 0)"

  12. #12
    Registered User
    Join Date
    12-05-2012
    Location
    victoria
    MS-Off Ver
    Excel 2010
    Posts
    55

    Re: object defined error

    thats great thanks, one last thing, what if I am unsure where it starts can i find the firstrow like you did the last row somehow??

  13. #13
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,646

    Re: object defined error

    It really depends on how the first row is determined.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1