vendredi 15 février 2019

If criteria meet copy and paste to specific rows

I'm having trouble with my code: Here is the thing, if column H = "Yes" then copy cell content from row "A" to another sheet on row "A", but starting at the first row.

The problem is: I want to paste the content to the first empty row after my header which is in cell "A7" not to the corresponding row from where the criteria meet. Also if there is a way to avoid blank cells between rows after copy and paste to organise them.

Option Explicit

Private Sub CommandButton1_Click()

'submacro which copies data over columns Dim lastRow As Long, i As Long 'determine last row in column H lastRow = Cells(Rows.Count, "H").End(xlUp).Row For i = 1 To lastRow

    'if Yes in H then copy from cell B in OFCE to cell B in DASHBOARD in    current row
    If Worksheets("OFCE").Cells(i, "H").Value = "Yes" Then
    'To paste from Dashboard tab to OFCE tab
        Worksheets("Dashboard").Cells(i, "A").Value = Worksheets("OFCE").Cells(i, "A").Value
    End If
Next

End Sub

After this i'll have to transfer not only one row, but many others.

Aucun commentaire:

Enregistrer un commentaire