+ Reply to Thread
Results 1 to 9 of 9

Using range with lastrow

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Using range with lastrow

    How do I use range with lastrow in this case?

    Range(("B" & lrTest - 1):("D" & lrTest - 1)).Select
    (this is what I tried, but it didn't work)

    If lastrow were 26, for example, it should be Range("B25":"D25")

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,892

    Re: Using range with lastrow

    Try this
    Range("B" & lrTest - 1 & ":D" & lrTest - 1).Select
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Using range with lastrow

    Do you need it to be in one line?
    Lastrow = ws.cells(1,2).end(xlDown).row
    ws.Range("B" & LastRow,"D" & LastRow)
    ...but that can be combined into one line.

    There are many ways to do that.
    <---If my answer helped, please click *

  4. #4
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Using range with lastrow

    Quote Originally Posted by joe31623 View Post
    Do you need it to be in one line?
    Lastrow = ws.cells(1,2).end(xlDown).row
    ws.Range("B" & LastRow,"D" & LastRow)
    ...but that can be combined into one line.

    There are many ways to do that.
    I wouldn't have to use the lastrow again because I already have a lastrow test on the top of the entire code. But it was a great help, thank you!! =)

  5. #5
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Using range with lastrow

    It worked!! Thank you =)

  6. #6
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Using range with lastrow

    ...I would avoid the .Select method whenever possible.

  7. #7
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Using range with lastrow

    Why? And what could I use to replace it?

  8. #8
    Forum Contributor
    Join Date
    12-05-2015
    Location
    Akron, OH
    MS-Off Ver
    15.0
    Posts
    424

    Re: Using range with lastrow

    Luuzmachado,

    I'd have to see how it's being used. Occasionally, you do need .Select, but I often see it used unnecessarily.
    .Select methods take up a lot of time and if it's used to .Copy/.Paste, there are better ways, namely: ws_dest.Range("A1").Cells.Value = rng_toCopy.Cells.Value.

    For more information about .Select alternatives and why there are better methods, see: http://www.businessprogrammer.com/po...-using-select/

    Practically speaking, it may not matter if you don't write a lot of code or if you're just moving a few things around.

    *The more you know*

  9. #9
    Forum Contributor
    Join Date
    01-03-2016
    Location
    Rio de Janeiro, Brazil
    MS-Off Ver
    2016
    Posts
    125

    Re: Using range with lastrow

    Thank you!! I'm sure it'll help me later =)
    Quote Originally Posted by joe31623 View Post
    Luuzmachado,

    I'd have to see how it's being used. Occasionally, you do need .Select, but I often see it used unnecessarily.
    .Select methods take up a lot of time and if it's used to .Copy/.Paste, there are better ways, namely: ws_dest.Range("A1").Cells.Value = rng_toCopy.Cells.Value.

    For more information about .Select alternatives and why there are better methods, see: http://www.businessprogrammer.com/po...-using-select/

    Practically speaking, it may not matter if you don't write a lot of code or if you're just moving a few things around.

    *The more you know*

+ 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] LastRow - for next loops longer than lastrow?
    By flabb in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-07-2016, 12:39 PM
  2. [SOLVED] BorderAround for Range (lastRow)
    By Quasis in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-06-2015, 03:01 PM
  3. [SOLVED] Changing range in VBA to lastrow
    By BlakeSkate in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 08-07-2015, 05:01 PM
  4. [SOLVED] How to select Range A1 to LastRow/LastColumn
    By tuongtu3 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 03-29-2014, 03:40 AM
  5. Creating a table with VBA using lastrow as range
    By washout in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-28-2013, 12:20 PM
  6. Copy From LastRow to LastRow+7
    By dvent in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 02-11-2010, 06:56 AM
  7. Copy from named range down until lastrow?
    By jazbath in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-19-2007, 05:56 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