+ Reply to Thread
Results 1 to 11 of 11

Selecting from firstrow to lastrow of data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Selecting from firstrow to lastrow of data

    Hi,

    I have a table of data, which will often change in length. I have defined the first row of and last row of data as:

    firstrow
    lastrow

    Is there a way to select these two rows as well as everything in between?

    Thanks
    Last edited by uncleslinky; 06-30-2011 at 05:14 AM.

  2. #2
    Registered User
    Join Date
    06-29-2011
    Location
    California
    MS-Off Ver
    Excel 2003/2007
    Posts
    58

    Re: Selecting from firstrow to lastrow of data

    Why do you need to select them? Typically there is a vba command that can reference those cells easily then execute the property adjustments you'd like.

  3. #3
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Selecting from firstrow to lastrow of data

    I need to paste special values, however I do not want to select the entire worksheet. I only want to paste special values within that range.

  4. #4
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Selecting from firstrow to lastrow of data

    If those two are actually named ranges:
    With Range("firstrow", "lastrow")
       .Value = .Value
    End With
    or if you are pasting from elsewhere:
    Range("firstrow", "lastrow").PasteSpecial xlPasteValues
    Everyone who confuses correlation and causation ends up dead.

  5. #5
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Selecting from firstrow to lastrow of data

    Hi guys,

    Apologies for the confusion. I meant to say I declared lastrow and firstrow as variables (not named ranges. Is my request still possible?

    I'm quite new to VBA so again apologies for any confusion

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Selecting from firstrow to lastrow of data

    How are they declared and what values do they have?

  7. #7
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Selecting from firstrow to lastrow of data

    firstrow is always row 4
    lastrow will be set my a user input box


    Dim firstrow As Long
    Dim lastrow As Long
    
    lastrow = InputBox("Enter Last Row")
    firstrow = Rows("4:4").Row

  8. #8
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Selecting from firstrow to lastrow of data

    Is the number of columns fixed? If so, which ones are they?

  9. #9
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Selecting from firstrow to lastrow of data

    Yes, columns A:AT

  10. #10
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    England
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,971

    Re: Selecting from firstrow to lastrow of data

    Dim firstrow As Long
    Dim lastrow As Long
    
    lastrow = InputBox("Enter Last Row")
    firstrow = 4
    
    Range(Cells(firstrow, "A"), cells(lastrow, "AT")).PasteSpecial xlpastevalues

  11. #11
    Forum Contributor
    Join Date
    04-06-2009
    Location
    England
    MS-Off Ver
    Excel 2007
    Posts
    103

    Re: Selecting from firstrow to lastrow of data

    Thanks :-D

+ 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