Consulting

Results 1 to 7 of 7

Thread: can anyone see an isue with this line? object defined error

  1. #1

    can anyone see an isue with this line? object defined error

    Hi all,
    this is where im having the issue and im unsure why.

    thanks for any help guys!

    Sheets("Management").Range(Cells(2, 1), Cells(finalrow, 1)).Select

  2. #2
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,873
    you probably haven't assigned anything to finalrow (make sure the spelling's right).
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  3. #3
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    If there is something valid in finalrow, then you might be not referencing the Management sheet. Some thoughts ...

    With Sheets("Management")
        .Select
        Range(.Cells(2, 1), .Cells(finalrow, 1)).Select
    End With

    No dot on Range, but dots on .Cells

  4. #4
    Hi thanks for the help but ive suused it, i didnt know the sheet had to be active.

  5. #5
    Knowledge Base Approver VBAX Wizard
    Joined
    Apr 2012
    Posts
    5,642
    That's the main reason you should refrain form 'select' and 'activate' in VBA

  6. #6
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    It only has to be active because of the way you were using it


    snb is very correct

    If for example, you wanted to copy the data to a another sheet

    With Sheets("Management") 
        call  Range(.Cells(2, 1), .Cells(finalrow, 1)).Copy (Worksheets ("Summary").Cells(45,1))
    End With
    That way it doesn't matter (aka "Keeps me out of trouble") which sheet is active, and it doesn't even have to be either of those two
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  7. #7
    VBAX Master Aflatoon's Avatar
    Joined
    Sep 2009
    Location
    UK
    Posts
    1,720
    Location
    There should really be a dot in front of Range too. If the code is in the module for a different sheet, you'll get an error otherwise.
    Be as you wish to seem

Posting Permissions

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