• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Data copy and paste in VBA

ThrottleWorks

Excel Ninja
Hi,

Please review attached file and help. I need to copy data from sheet 1 and paste it in sheet 2 of the same file.

ABC, DEF, GHI, JKL & MNO or unique values.
The format of Input sheet will be as provided in sample file.

There will always one blank row between two tables.

Can anyone please help me in this.
 

Attachments

  • Chandoo.xls
    25 KB · Views: 5
Last edited:
Something to start with:

Code:
Sub MoveData()
Dim lastRow, i As Long
    Sheets("Sheet1").Select
    lastRow = Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    For i = 2 To lastRow
        If Range("B" & i) = "" Then
          Range("E" & i).Value = Range("A" & i).Value
        Else
          Range("E" & i).Value = Range("E" & i - 1).Value
        End If
    Next i
    Range("A1:E" & lastRow).AutoFilter Field:=2, Criteria1:="<>"
    ActiveSheet.Range("E1:E" & lastRow).SpecialCells(xlCellTypeVisible).Copy
    Sheets("Sheet2").Range("A1").PasteSpecial
    ActiveSheet.Range("A1:D" & lastRow).SpecialCells(xlCellTypeVisible).Copy
    Sheets("Sheet2").Range("B1").PasteSpecial
    Application.CutCopyMode = False
    ActiveSheet.AutoFilterMode = False
    Range("E:E").Clear
End Sub

Also file with code is attached.
 

Attachments

  • Chandoo.xls
    41 KB · Views: 6
Back
Top