【问题标题】:Formula to apply to delete blank cells and the cell next to it for multiple columns应用于删除空白单元格及其旁边的单元格以用于多列的公式
【发布时间】:2015-01-25 15:20:25
【问题描述】:

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

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

在随附的 Excel 数据表中,有 2 列并排用线标记(TIME 和 GLU)。我使用条件格式突出显示(红色)每个 GLU 列中的空白单元格。我想要做的(不必手动完成......)是删除这些空白单元格(即删除并向上移动整列)并且还删除并向上移动紧邻每个左侧的单个“时间”单元格这些空白单元格中的一个(例如,如 B 列旁边的 A 列中绿色突出显示的 TIME 单元格所示)。

有没有人知道这可能是如何通过代码实现的?会非常有帮助!

提前致谢! 帕特里克

【问题讨论】:

    标签: excel vba


    【解决方案1】:
    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
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-02
      相关资源
      最近更新 更多