+ Reply to Thread
Results 1 to 11 of 11

Last row starting from row A

  1. #1
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Last row starting from row A

    Hello. I'd like to paste into A and THEN offset by 1 row. This code starts in A2 unfortunately. How could I modify it? Also, why do I have to write PasteSpecial xl PasteAll? Couldn't I just write Paste? Thanks.


    Please Login or Register  to view this content.

  2. #2
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Last row starting from row A

    It's starting in A2 because you have Offset(1)

    Generally, you will need to do that to not overwrite the value in a table's last row.

    You could check to see if you are at the top of the sheet, or if the value is blank,
    Please Login or Register  to view this content.
    For the pasteSpecial versus paste, just try it both ways and see what happens. Generally, you want to clean your code of this kind of statement anyway.

    If you are trying to copy over some values, there are better ways to do that.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  3. #3
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    Makes sense. Thanks!!

  4. #4
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    I tried this with my code but it doesn't seem to work. The first part copies into A1 but then the rest of the line items don't copy anything.

    Please Login or Register  to view this content.

  5. #5
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Last row starting from row A

    Just as I suspected... there is no need for the .copy / .pasteSpecial funny business.

    Here's what I suggest instead.

    Please Login or Register  to view this content.

    Barring any typos (I just typed that into the browser) that should do it. You can just equate the values and avoid the copy/paste stuff. It's a really good habit to get away from, it's something we all do at one point because the Macro recorder does it....

  6. #6
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Last row starting from row A

    Hi ammartino,

    It looks like you are starting to learn to program in VBA and Excel. Each of us develops a style of programming that we understand.

    One of the first problems is to extract a cell using VBA. Here are a few ways to get the stuff out of B7.
    Range("B7")
    Cells(7, "B")
    Read my favorite author's answer at: http://spreadsheetpage.com/index.php...your_vba_code/

    I rarely use any "Offset" methods in my programming as it needs to know what cell the offset is from and this is one more level of confusion for me.

    The next style concern is to use a For Next construct or a For Each construct.

    I prefer the older For Next construct as I like to know each row and column I'm working with.

    I also don't like to use variable names of j,k,l as a more meaningful name makes code much more readable.

    See which of these two subs make more sense. What kind of coder do you want to be?

    Please Login or Register  to view this content.
    Look at http://www.excelfunctions.net/VBA-Co...sentation.html for a start to indentation and line breaks.
    Last edited by MarvinP; 03-12-2015 at 02:26 PM.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  7. #7
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    Hey General. It still doesn't work. At the third line it returns "subscript out of range". Not sure why.

  8. #8
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    Hi Marvin. I like your code examples, but the problem is that they copy to the same cell in sheet 2, whereas I would like them to copy into A1, A2, A3, etc.

  9. #9
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Last row starting from row A

    OK - I missed that part of the problem. No problem reading my code...
    How about this then.

    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    Thanks Marvin. This still has the same issue of copying into A2, not A1 because you are adding 1 to the last row.

  11. #11
    Forum Contributor
    Join Date
    08-14-2013
    Location
    LA Baby!!
    MS-Off Ver
    Excel 2007
    Posts
    1,598

    Re: Last row starting from row A

    I thought this might work but it's not for some reason. On the second if statement it doesn't read the lastrow right.

    Please Login or Register  to view this content.

+ 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. Just starting
    By davids4500 in forum Hello..Introduce yourself
    Replies: 3
    Last Post: 07-17-2014, 08:54 AM
  2. Trouble with spreadsheet layout and connecting multiple sheets
    By jbradley in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-18-2013, 06:51 PM
  3. Replies: 5
    Last Post: 09-27-2012, 07:30 PM
  4. Doublecheck with second lookup starting starting after first match
    By zekethewolf in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2011, 06:36 AM
  5. [SOLVED] Starting with A2!
    By Alen32 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-05-2005, 06:06 AM

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