1

我有列第 1 行是标题..

IF Column C doesn't have data in entire column then delete C D E F
IF Column D doesn't have data in entire column then delete D E F
IF Column E doesn't have data in entire column then delete E F
IF Column F doesn't have data in entire column then delete F

以同样的方式前往 NN

IF Column G doesn't have data in entire column then delete G H I J K L M N 
IF Column H doesn't have data in entire column then delete H I J K L M N 
IF Column I doesn't have data in entire column then delete I J K L M N 
IF Column J doesn't have data in entire column then delete J K L M N 
IF Column K doesn't have data in entire column then delete K L M N 
IF Column L doesn't have data in entire column then delete L M N 
IF Column M doesn't have data in entire column then delete M N 
IF Column N doesn't have data in entire column then delete N


A   B   C   D   E   F   G   H   I   J   K   L   M   N   O   P   Q   R
TI1 TE2 TT1 TT2 TT3 TT4 NN1 NN2 NN3 NN4 NN5 NN6 NN7 NN8 CMT K2  K3  
BLAH    BLAH
4

2 回答 2

2

我会通过添加一个额外的行来解决这个问题(你以后可以随时隐藏它)。

假设您的标题在第 1 行,然后在第 2 行中添加一个额外的(帮助)行。

  • 在 C2 中,输入以下公式(替换C30为适合您的值):

    =COUNTA(C3:C30)

  • 在 D2 中,输入以下公式:

    =IF(C2=0,0,COUNTA(D3:D30))

  • 将该公式拖到 E & F

  • 在 G 中重做 C 的公式

  • 在 H 中重做 D 的公式并拖到 N

... ETC。

现在只需编写一个非常简单的宏来删除 row2 的值 = 0 的任何列。

这对我来说似乎是最简单的方法,但还有很多其他方法。

希望这可以帮助!!

于 2013-02-21T15:35:23.220 回答
0

这个宏做你的第一点——第二阶段将非常相似。

您需要将5s 更改为表格的长度。

GoTo一般不喜欢,但我在这段代码中使用了它。

Sub firstbit()

If Excel.WorksheetFunction.CountA(ActiveSheet.Range("C2:C5")) = 0 Then
    Excel.ActiveSheet.Range("C2:F5").clearcontents
    GoTo FirstStageComplete:
End If
If Excel.WorksheetFunction.CountA(ActiveSheet.Range("D2:D5")) = 0 Then
    Excel.ActiveSheet.Range("D2:F5").clearcontents
    GoTo FirstStageComplete:
End If
If Excel.WorksheetFunction.CountA(ActiveSheet.Range("E2:E5")) = 0 Then
    Excel.ActiveSheet.Range("E2:F5").clearcontents
    GoTo FirstStageComplete:
End If
If Excel.WorksheetFunction.CountA(ActiveSheet.Range("F2:F5")) = 0 Then
    Excel.ActiveSheet.Range("F2:F5").clearcontents
End If
FirstStageComplete:

End Sub
于 2013-02-21T17:11:00.540 回答