应用于删除空白单元格及其旁边的多列单元格的公式

Formula to apply to delete blank cells and the cell next to it for multiple columns

想知道是否有人可以帮助我解决附带的示例数据集的问题。我还有很多,所以想找出一种有效的方法来做到这一点:

https://www.dropbox.com/s/fa32ddeh4lbz8lo/Problem%20removing%20blanks%20cells%20and%20corresponding%20left%20cell.xlsx?dl=0

在所附的 excel 数据中 sheet 是一组由 2 列并排标记的行(TIME 和 GLU)。我使用条件格式来突出显示(红色)每个 GLU 列中的空白单元格。我想要做的(无需手动完成......)是删除这些空白单元格(即删除并向上移动整列)并且还删除并向上移动单个 'TIME' 单元格立即向左这些空白单元格中的每一个(如 A 列和 B 列中绿色突出显示的 TIME 单元格所示)。

有没有人知道如何通过代码实现这一点?会非常有帮助!!

提前致谢! 帕特里克

Sub RemoveBlank()
Dim sht As Worksheet
Dim LastRow As Long
Dim LastColumn As Long
Dim Column As Long

Application.ScreenUpdating = False
Set sht = ThisWorkbook.Worksheets("Sheet1")

LastColumn = sht.Cells(1, sht.Columns.Count).End(xlToLeft).Column
Column = 2

Do While Column <= LastColumn
    LastRow = sht.Range(Cells("1", Column - 1), Cells("1", Column - 1)).CurrentRegion.Rows.Count
    Row = LastRow
    Do While Row > 1
        If sht.Range(Cells(Row, Column), Cells(Row, Column)).Value = "" Then
            'Delets the two column row with a blank GLU and moves the rest of the data up.
            sht.Range(Cells(Row, Column - 1), Cells(Row, Column)).Select
            Selection.delete Shift:=xlUp
        Else
            'Do nothing
        End If
        Row = Row - 1
    Loop
    Column = Column + 2
Loop

Application.ScreenUpdating = True
End Sub