Results 1 to 8 of 8

Ranges with same address behaving differently with offset

Threaded View

  1. #1
    Forum Expert
    Join Date
    06-26-2010
    Location
    Austin, TX
    MS-Off Ver
    Excel 2010
    Posts
    1,673

    Ranges with same address behaving differently with offset

    I can probably work around this, but I don't understand why it is happening.
    The attached spreadsheet has everything set up. Here is the code:
    Option Explicit
    
    Sub weird()
    
    Dim goodr, badr As Range
    Dim x, y, lrow As Long
    
    lrow = Cells(Rows.Count, 2).End(xlUp).Row
    x = Sheets("Sheet1").Range("1:1").Find("d").Column
    y = Sheets("Sheet1").Range("1:1").FindPrevious.Column
    Set badr = Columns(x).Resize(lrow, y - x + 1)
    
    Range("A10") = "badr address is: " & badr.Address
    
    Set goodr = Range("D1:F7")
    
    Range("A11") = "goodr address is: " & goodr.Address
    
    Range("A12") = "badr(2) address is: " & badr(2).Address
    Range("A13") = "goodr(2) address is: " & goodr(2).Address
    
    End Sub
    Here is the output:
    badr address is: $D$1:$F$7
    goodr address is: $D$1:$F$7
    badr(2) address is: $E$1:$E$7
    goodr(2) address is: $E$1

    I don't understand how these two ranges can have the same address, yet behave differently when using the (2) offset. I thought it always went by cell (and that is what my other code was expecting).

    Thanks
    Attached Files Attached Files
    Pauley
    --------
    If I helped with your issue, I'd appreciate a rep bump (hit the '*' icon to the bottom left of this post).

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Macro behaving differently depending on how it is called
    By louiserace in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 05-13-2016, 09:53 AM
  2. [SOLVED] VBA code behaving differently when stepping
    By Durarara in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 03-18-2016, 05:20 PM
  3. [SOLVED] 2 copies of Excel 2010 behaving differently.
    By JennyW1983 in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 11-09-2015, 04:36 AM
  4. Replies: 9
    Last Post: 07-17-2015, 04:08 PM
  5. [SOLVED] Enable / Disable Macros behaving differently in Excel 2003 from Windows XP to Windows 7
    By TC1980 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 06-21-2013, 09:09 AM
  6. [SOLVED] OFFSET behaving oddly
    By Ryan Poth in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-30-2006, 02:30 AM
  7. need help using the offset function differently
    By Marshin in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 03-16-2005, 12:06 PM

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