自动安排数据

时间:2018-07-03 06:22:54

标签: vba

有什么安排的方式吗?像所附图片一样?

*要求是,当A列单元格为空时,B列值将移至B列单元格中以前的非空列A行。

Example Photo

1 个答案:

答案 0 :(得分:1)

尝试此代码

Sub Macro1()

Dim i As Long
 i = 1
  Do Until Cells(i, 2) = ""
    If Cells(i, 1) = "" Then
    On Error Resume Next
     Cells(i - 1, 2) = Cells(i - 1, 2) & "," & Cells(i, 2)
       Cells(i, 2).EntireRow.Delete
          i = i - 1
        End If
         i = i + 1
        Loop

End Sub