+ Reply to Thread
Results 1 to 5 of 5

Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

  1. #1
    Registered User
    Join Date
    01-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    76

    Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

    Hi guys,

    I am learning VBA. So, I have a set of data just as below:

    A1=10
    A2=(blank)
    A3=20
    A4=(blank)
    A5=30
    A6=(blank)
    A7=(blank)
    A8=40
    A9=(blank)
    A10=(blank)
    A11=50

    [A11 is the cell at the last row that contains value]

    How can I write a VBA so the result become:
    A1=10
    A2=10
    A3=20
    A4=20
    A5=30
    A6=30
    A7=30
    A8=40
    A9=40
    A10=40
    A11=50

    Thanks in advance.
    Last edited by Beginner Level; 07-09-2014 at 03:34 AM.

  2. #2
    Forum Guru sktneer's Avatar
    Join Date
    04-30-2011
    Location
    Kanpur, India
    MS-Off Ver
    Office 365
    Posts
    9,648

    Re: Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

    You may try this....
    Please Login or Register  to view this content.
    Regards
    sktneer


    Treat people the way you want to be treated. Talk to people the way you want to be talked to.
    Respect is earned NOT given.

  3. #3
    Registered User
    Join Date
    01-13-2012
    Location
    Singapore
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    76

    Re: Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

    Thank you very much. So let say the above condition is in first row instead of first column, can i modified the code like below?

    Sub CopyCells()
    Dim rng, cell As Range
    Dim lr As Long
    lr = Cells(1, Columns.Count).End(xlToLeft).Column

    Set rng = Range(lr & "A1:1")
    For Each cell In rng
    If cell = "" Then
    cell = cell.Offset(0, -1)
    End If
    Next cell
    End Sub

  4. #4
    Valued Forum Contributor
    Join Date
    03-21-2013
    Location
    cyberia
    MS-Off Ver
    Excel 2007
    Posts
    457

    Re: Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

    first column
    Please Login or Register  to view this content.
    first row
    Please Login or Register  to view this content.
    it's usually a good idea to put On Error Resume Next as first line in these special cells codes to void error in event of no blank cells

    can also re-size the column or row to include only the first 11 elements if that's what's wanted

    if your "copy and paste" is to include cell formats then can use different approach (for columns, mutatis mutandis for rows)
    Please Login or Register  to view this content.

  5. #5
    Forum Contributor
    Join Date
    05-01-2020
    Location
    CHENNAI
    MS-Off Ver
    EXCEL 2010
    Posts
    105

    Re: Copy Cell From One Cell and Paste to next blank cell, Loop until last row/column

    Hi this is working for data in Column A1. how to modify this code for selection of data in any column

+ 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. Need loop to copy value on a column until cell adjacent to it is blank.
    By boonboonzzz in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-10-2014, 02:04 AM
  2. [SOLVED] Loop through column check for colored cell and copy that cell to cells below it.
    By RENCE19 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-15-2013, 04:51 AM
  3. Copy valule from one column and then paste only blank cell to other worksheet
    By tantcu in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-16-2013, 12:42 PM
  4. find last non blank cell in a column and copy paste in next row
    By prasad_tavva in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-31-2007, 09:41 AM
  5. [SOLVED] Paste blank cell row loop
    By Ron Dean in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 01-19-2006, 05:10 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