+ Reply to Thread
Results 1 to 5 of 5

Range.End(xlDown) is selecting values above the reference cell.

  1. #1
    Registered User
    Join Date
    08-25-2017
    Location
    Savannah, GA
    MS-Off Ver
    2010
    Posts
    9

    Range.End(xlDown) is selecting values above the reference cell.

    Hello,

    I am new to VBA and am kind-of teaching myself how to use it. I haven't had any luck finding any info about my particular issue, so any help you could provide would be greatly appreciated.

    I have a sheet where cells A1:A50 all have values, but the last cell, A50, is variable, so sometimes it may go down to A100 or whatever. What I want to do is use the amount of cells in the A column as a reference to autofill (right now I'm just testing with selecting the cells) cells in columns where the active cell is, I'm not starting from A1, the valid info actually starts at A8. What I have right now works great except for one problem. If all the cells from A1 through A50 are filled, then it works and selects down to the last cell and I get a selection of equivalent cells in the actively selected column (i.e. D8:D50), but, it any cell above cell A8 is blank, then it no longer selects down to row 50, it now selects up to the first blank cell. If cell A2 is empty, then it will now select D2:D8 instead of D8:D50. How can I get it so ignore blank cells above the starting cell? Isn't xlDown supposed to go down?


    Sub SelectOffsetOfColumnA()
    'Uses cells in column A as a reference for selection length and selects cells in the same column as the active cell. Starts at A8 and stops at the first empty row in column A.

    Dim N As Long
    N = Cells(1, 1).End(xlDown).Row
    Range("A8:A" & N).Offset(0, ActiveCell.Column - 1).Select

    End Sub

  2. #2
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Range.End(xlDown) is selecting values above the reference cell.

    Try:

    Please Login or Register  to view this content.
    Last edited by xladept; 01-05-2018 at 01:12 PM.
    If I've helped you, please consider adding to my reputation - just click on the liitle star at the left.

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~(Pride has no aftertaste.)

    You can't do one thing. XLAdept

    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~aka Orrin

  3. #3
    Registered User
    Join Date
    08-25-2017
    Location
    Savannah, GA
    MS-Off Ver
    2010
    Posts
    9

    Re: Range.End(xlDown) is selecting values above the reference cell.

    xladept,

    Thank you. This does work, except for one thing that I forgot to mention in my original post. I need this to select all cells up to the first blank cell. What I am ultimately going to be doing is having one formula doing this for cells A8-A50, then there will be a few blank rows, then there will be another set of data, say, from A60 to A100, which will use the same (but modified for reference cell) formula to cover that block of cells.

  4. #4
    Registered User
    Join Date
    08-25-2017
    Location
    Savannah, GA
    MS-Off Ver
    2010
    Posts
    9

    Re: Range.End(xlDown) is selecting values above the reference cell.

    I figured it out. What was going on is that in my formula for N, I had N = Cells(1, 1).End(xlDown).Row, which made it start from cell A1 and count down to the next blank cell. I changed the formula to N = Cells(8, 1).End(xlDown).Row, and now it starts from the cell I need it to, A8. Thanks.

  5. #5
    Forum Guru xladept's Avatar
    Join Date
    04-14-2012
    Location
    Pasadena, California
    MS-Off Ver
    Excel 2003,2010
    Posts
    12,378

    Re: Range.End(xlDown) is selecting values above the reference cell.

    Welcome!

+ 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. Replies: 2
    Last Post: 09-01-2017, 05:43 PM
  2. [SOLVED] Selecting a cell reference from a named range.
    By Yoepy in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-22-2015, 08:57 PM
  3. Replies: 5
    Last Post: 08-21-2014, 09:10 AM
  4. RE-WRITING WITH RANGE.END(xlDown)
    By dalewms2 in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 09-02-2011, 11:09 AM
  5. Selecting a range with relative reference
    By HBF in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-12-2008, 04:45 PM
  6. Unable to get last filled cell address from Range.End(xlDown) method
    By vedpatel in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-28-2006, 05:15 AM
  7. [SOLVED] Selecting a range using a column number reference
    By PCLIVE in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 10-14-2005, 12:05 PM

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