Cutting Row with Data and moving to different sheet VBA

前端 未结 1 916
无人及你
无人及你 2020-12-18 15:45

I\'m trying to cut a row that has the specified cell blank and then paste it into another sheet in the same workbook. My coding works fine to delete the row but everything

相关标签:
1条回答
  • 2020-12-18 16:08

    If you want to cut and paste, see below:

    With Sheet1
        .Range("A1").Cut Sheeet2.Range("A1")
    End With
    

    Above cut's value in Cell A1 in Sheet1 and paste it on Cell A1 of Sheet2.
    Now if you want to incorporate it in your code, see below.

    Dim i As Long: i = 1
    With Activesheet
        For n = nLastRow To nFirstRow Step -1
            If .Cells(n, "G") = "" Then
                .Cells(n, "G").EntireRow.Cut Sheet2.Cells(i, "A")
                .Cells(n, "G").EntireRow.Delete '~~> if you want to delete
                i = i + 1
            End If
        Next
    End With
    

    Above code cuts all rows with Cell in G blank and paste it in Sheet2 starting A1.
    Note: Sheet2 and Sheet1 that I used above are sheet codenames.

    0 讨论(0)
提交回复
热议问题