+ Reply to Thread
Results 1 to 8 of 8

What is an alternative to Union() when referring to multiple cells?

  1. #1
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    What is an alternative to Union() when referring to multiple cells?

    I have the following line from a plotting script I made:

    Please Login or Register  to view this content.
    It works fine in Excel 2010, but fails in Excel 2003.

    The variable y is dimensioned as an integer and is either 0 or 1. When it gets to the two lines highlighted in red I get a Run-time error '1004': Method 'Cells' of object '_Global' failed. y is referenced many times prior to that line of code without issue, so I just appears to be a problem with how I attempt to select two different cells on the worksheet.

    Thanks!
    Last edited by Dante_Blake; 05-08-2012 at 09:15 AM.

  2. #2
    Forum Contributor
    Join Date
    03-22-2012
    Location
    OR, USA
    MS-Off Ver
    Excel 14/2010
    Posts
    273

    Re: What is an alternative to Union() when referring to multiple cells?

    Can you upload your worksheet as a reference?

  3. #3
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: What is an alternative to Union() when referring to multiple cells?

    I can't, it's way too big for my available upload speed.

    I know you can select multiple ranges like:

    Please Login or Register  to view this content.
    However, if I remove teh quotes and replace the letter/number cell address, it will treat it as a start and end for one large range.

  4. #4
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: What is an alternative to Union() when referring to multiple cells?

    you haven't said what the problem actually is?
    Josie

    if at first you don't succeed try doing it the way your wife told you to

  5. #5
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: What is an alternative to Union() when referring to multiple cells?

    I modified the original post to [hopefully] better state the issue.

  6. #6
    Valued Forum Contributor StevenM's Avatar
    Join Date
    03-23-2008
    Location
    New Lenox, IL USA
    MS-Off Ver
    2007
    Posts
    910

    Re: What is an alternative to Union() when referring to multiple cells?

    What is an alternative to Union() when referring to multiple cells?
    A comma is the Union operator.

    Please Login or Register  to view this content.
    Thus:

    Please Login or Register  to view this content.
    For example, if y = 2:
    Then Range("C" & 3 + 7 * y & ",C" & 5 + 7 * y).Address = "$C$17,$C$19"
    And Union(Cells(3 + 7 * y, 3), Cells(5 + 7 * y, 3)).Address = "$C$17,$C$19"

  7. #7
    Forum Guru JosephP's Avatar
    Join Date
    03-27-2012
    Location
    Ut
    MS-Off Ver
    2003/10
    Posts
    7,328

    Re: What is an alternative to Union() when referring to multiple cells?

    you need to refer to the sheet the cells are on. also better not to select stuff
    Please Login or Register  to view this content.
    note the periods before the Cells calls to refer them back to the worksheet object referred to by the With statement.

  8. #8
    Registered User
    Join Date
    09-19-2011
    Location
    Atlanta, GA
    MS-Off Ver
    Excel 2010
    Posts
    32

    Re: What is an alternative to Union() when referring to multiple cells?

    Neither of those worked for me. I ended up doing the following:

    Please Login or Register  to view this content.
    Which is just a recorded macro I hacked up to include the differing rows.

+ 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