+ Reply to Thread
Results 1 to 9 of 9

Difference between Last Row & Last Column VBA

  1. #1
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Difference between Last Row & Last Column VBA

    Hello,

    I use lrow = Range("a" & Rows.Count).End(xlUp).Row quite often for the last row. Now I'm looking for the last column so I tried lcolumn = Range("6" & Columns.Count).End(xlLeft).Column but that does not work and I would love to know why.

    My ultimate goal is to use the lcolumn variable to help my sort. I tried using activeworksheet.usedrange.columns.count, but that returned a number so I think that is why it did not work with Range("a6:" & lcolumn & "23").Select when selecting my sort range.

    Thank you for any assistance!

    Luke

  2. #2
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: Difference between Last Row & Last Column VBA

    can you put your entire coding please

  3. #3
    Forum Expert Solus Rankin's Avatar
    Join Date
    05-24-2013
    Location
    Hollywood, CA
    MS-Off Ver
    Win7 Office 2010 VS Express 2012
    Posts
    2,655

    Re: Difference between Last Row & Last Column VBA

    try:
    Please Login or Register  to view this content.
    Remember this returns the last column as an integer (or long depending on how you have it DIMed) not a column letter.
    Thanks,
    Solus


    Please remember the following:

    1. Use [code] code tags [/code]. It keeps posts clean, easy-to-read, and maintains VBA formatting.
    Highlight the code in your post and press the # button in the toolbar.
    2. Show appreciation to those who have helped you by clicking below their posts.
    3. If you are happy with a solution to your problem, mark the thread as [SOLVED] using the tools at the top.

    "Slow is smooth, smooth is fast."

  4. #4
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: Difference between Last Row & Last Column VBA

    try that..yuo put a 6 into range which is not suppose to

    1 Column = Range("f" & Columns.Count).End(xlUp).Column

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: Difference between Last Row & Last Column VBA

    Luke

    "6" & Columns.Count won't produce a valid address so it can't be use with Range.

    Try using Cells instead.

    For example to find the last column in row 6.
    Please Login or Register  to view this content.
    You can also use Cells for Range("a6:" & lcolumn & "23").Select, but in a slightly different way.
    Please Login or Register  to view this content.
    If posting code please use code tags, see here.

  6. #6
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: Difference between Last Row & Last Column VBA

    Please Login or Register  to view this content.

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

    Re: Difference between Last Row & Last Column VBA

    Here's a couple of finders for last column and last row that I copied from Was Wodge a while back:

    Please Login or Register  to view this content.
    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

  8. #8
    Forum Contributor
    Join Date
    09-13-2012
    Location
    Midwest
    MS-Off Ver
    Excel 365
    Posts
    124

    Re: Difference between Last Row & Last Column VBA

    Thank you all for the fast and accurate replies. I was able to figure out how to select my range and go through the sort by using "Cells" instead of "Range". Funny how I always search for an answer for 2 hours, then I post, then I usually figure it out right after I post.
    Thank you for your time, I'm sure I'll be posting again soon.

    Luke

  9. #9
    Forum Contributor
    Join Date
    04-26-2013
    Location
    Canada
    MS-Off Ver
    Excel 2007
    Posts
    167

    Re: Difference between Last Row & Last Column VBA

    add reputation to the members that helped you and make the topic solved!

+ 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