Results 1 to 4 of 4

Thread: Autofill the data based on non blank cell in next row?

  1. #1
    Member
    Join Date
    Aug 2011
    Posts
    92
    Rep Power
    13

    Autofill the data based on non blank cell in next row?

    Hi,

    Need a code to autofill the data based on non blank cell in next row (to Right).
    For example row 3 has data from A3 till e3 and I have a value in A2 which I wants to autofill to E2.

    Thanks
    Rajesh

  2. #2
    Administrator Admin's Avatar
    Join Date
    Mar 2011
    Posts
    1,122
    Rep Power
    10
    Hi Rajesh,

    try this. adjust the range.

    Code:
    Sub kTest()
        
        Dim r   As Range, k, i As Long, c As Long
        
        Set r = Intersect(ActiveSheet.UsedRange, Range("a:e")) '<<=== adjust the range(a:e) part
        
        With r
            .Columns(1).Insert
            .Columns(1).Offset(, -1).FormulaR1C1 = "=counta(rc[1]:rc[" & .Columns.Count & "])"
            k = .Columns(1).Offset(, -1).Resize(, .Columns.Count + 1).Value
            For i = 1 To UBound(k, 1)
                If k(i, 1) = 1 Then
                    If i + 1 <= UBound(k, 1) Then
                        For c = 2 To UBound(k, 2)
                            k(i, c) = k(i + 1, c)
                        Next
                        i = i + 1
                    End If
                End If
            Next
            .Columns(1).Offset(, -1).Resize(, .Columns.Count + 1) = k
            .Columns(1).Offset(, -1).Delete
        End With
        
    End Sub
    Cheers !

    Excel Range to BBCode Table
    Use Social Networking Tools If You Like the Answers !

    Message to Cross Posters

    @ Home - Office 2010/2013/2016 on Win 10 (64 bit); @ Work - Office 2016 on Win 10 (64 bit)

  3. #3
    Member
    Join Date
    Aug 2011
    Posts
    92
    Rep Power
    13

    Autofill the data based on non blank cell in next row?

    Hi Admin,

    Thanks for your quick reply. This code solved my other issue
    However, i am still struggling with my current issue. This code Autofill the same value i have in other row. But i am looking to autofill the value I have in target row.

    The attached file will clarify it.

    Autofill.xlsx

    Thanks in advance

    Rajesh

  4. #4
    Member
    Join Date
    Aug 2011
    Posts
    92
    Rep Power
    13
    Hi,

    Got a solution , not sure how professional it is, but worked for me.

    HTML Code:
    Sub test2()
    LastCol = Range("A2").End(xlToRight).Column
    lastrow = Range("B2").End(xlUp).Row
    Debug.Print lastrow, LastCol
    Range("A1").AutoFill Destination:=Range("A1", Cells(1, LastCol)), Type:=xlFillDefault
    
    End Sub
    Thanks
    Rajesh

Similar Threads

  1. Replies: 2
    Last Post: 05-30-2013, 07:28 PM
  2. Replies: 2
    Last Post: 03-05-2013, 07:34 AM
  3. Replies: 4
    Last Post: 02-22-2013, 02:24 AM
  4. Group Pivot Data Based On Row Values In One Column
    By mrmmickle1 in forum Excel Help
    Replies: 10
    Last Post: 10-09-2012, 11:46 PM
  5. Replies: 2
    Last Post: 09-24-2012, 11:19 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •