+ Reply to Thread
Results 1 to 10 of 10

Problemas with object assignation in hierachy Range.Offset.Range

  1. #1
    Registered User
    Join Date
    03-18-2014
    Location
    Venezuela
    MS-Off Ver
    2007, 2010, 2013
    Posts
    5

    Problemas with object assignation in hierachy Range.Offset.Range

    I have been experiencing some problems with this hieranchy: Range.Offset.Range, and I would like to know if anyone knows why this could be happening. I have several ways to make my function work, but I would like to know if there is an specific reason for such error.

    Here's the thing: I am using a range called "MPOS_XX", where XX is an integer between 01 and 30, as relative reference. Then I need to work with some data near this range. In order to ease the syntaxis, I decided to assign this offset to a Range Object. The last three rows of the code reflect what I do. This function is not used in the worksheet, it is used in a module.

    Please Login or Register  to view this content.
    The problem is that whenever a run my code, error 1004 appears! Curious thing: If I go to the workbook and select the worksheet WS_02, the code runs smoothly without problems.

    Before you post any comments, be aware of the following:

    Please Login or Register  to view this content.
    This is not what I intend to do! This syntasis references a different group of cells from what I need.

    Hope anyone has an idea.

    In case you need to run the code, you will need this function:

    Please Login or Register  to view this content.
    In case you need the workbook, it is attached to the message.

    Regards,
    Attached Files Attached Files

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    have you tried:
    Please Login or Register  to view this content.
    and so on?
    Best Regards,

    Kaper

  3. #3
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,863

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    PS. Also to try:
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    03-18-2014
    Location
    Venezuela
    MS-Off Ver
    2007, 2010, 2013
    Posts
    5

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    Yeap.. the problem is gone. Better syntaxis and better use of the Range object properties. I Like it!

    Though, any ideas on the original problem?

  5. #5
    Registered User
    Join Date
    03-18-2014
    Location
    Venezuela
    MS-Off Ver
    2007, 2010, 2013
    Posts
    5

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    In case someone else is working on this, there was a little problem in the function. Trying to find a different solution, I worked this function as a subroutine. Please consider the following modification to the loop:

    Please Login or Register  to view this content.

  6. #6
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    I think first code must be:
    Please Login or Register  to view this content.
    or with addresses:
    Please Login or Register  to view this content.
    • Please remember to mark threads Solved with Thread Tools link at top of page.
    • Please use code tags when posting code: [code]Place your code here[/code]
    • Please read Forum Rules

  7. #7
    Registered User
    Join Date
    03-18-2014
    Location
    Venezuela
    MS-Off Ver
    2007, 2010, 2013
    Posts
    5

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    Izandol, thanks foryour suggestion.

    Regarding the first block of code, please consider my original post. That syntaxis refereces other cells, different from what I need.

    My question is focussed on the behavior of VBA using the hierachy Range.Offset.Range(cells, cells); it should work either using addresses or the property 'Cells'. Considering the object logic, Range.Offset yields a Range object. And the Range object has an Range property which I can access using addresses or the property cells.

  8. #8
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    I do not think you have tested my suggestion. This is not the same as what you have suggested - this With statement holds reference to Worksheet, not to Range object as you have.

  9. #9
    Registered User
    Join Date
    03-18-2014
    Location
    Venezuela
    MS-Off Ver
    2007, 2010, 2013
    Posts
    5

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    Izandol,

    You were absolutely right. I have not seen that the solution you suggested is different from what I wrote. And it worked perfectly. After internalizing the error, I think that VBA was in conflict 'cause both the worksheet and the range object have a Cells property. Of course, when I selected the worksheet in the workbook, I thing VBA choose the Worksheet over the range object to reference the Cells property.

    Thnaks for your support, both Izandol and Kaper! Administrator, you can consider this thread as solved!

    Regards,

    Rubén

  10. #10
    Forum Guru Izandol's Avatar
    Join Date
    03-29-2012
    Location
    *
    MS-Off Ver
    Excel 20(03|10|13)
    Posts
    2,581

    Re: Problemas with object assignation in hierachy Range.Offset.Range

    If that takes care of your original question, please select Thread Tools from the menu link above and mark this thread as SOLVED. Thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Define new range names based on existing range name offset 1 column to right
    By jprlimey in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-03-2014, 07:53 PM
  2. Replies: 1
    Last Post: 01-23-2013, 03:00 PM
  3. Dynamic Range using Offset, range not found for Pivot
    By GoneBaja in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 09-08-2012, 09:19 AM
  4. Range Question / error 1004: method Range of object Worksheet has failed
    By Paul in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-07-2005, 10:06 AM
  5. [SOLVED] Range Object with Find and Offset
    By Ctal in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-03-2005, 11:06 AM

Tags for this Thread

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