2013-02-21 68 views
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 
+0

我看到矛盾:每一列都有標題。 「列C如何在整列中沒有數據」可能是可能的? – 2013-02-21 15:27:40

+0

99.999%它會有數據,但是太陽從其他方向上升可能有數據,如果C沒有數據,那麼100%D E F將不會有數據。 – Mowgli 2013-02-21 15:41:58

+0

Pal,如果列有標題 - 它不能是全空的!請提供確切的條件。 – 2013-02-21 15:46:31

回答

2

我會通過額外添加做到這一點行來處理事情(你可以隨時隱藏它)。

假設你的標題在第1行,然後在第2行添加一個額外的(幫助者)行。

  • 在C2,把下式(與你的一個適當的值替換C30)中:

    =COUNTA(C3:C30)

  • 在D2,把下面的公式中:

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

  • 將該公式拖到E &˚F

  • 重做C'S G中

    公式
  • 重做D的H +及拖動公式跨越到N

...等

現在它只是一個寫一個非常之事簡單的宏來刪除row2的值爲0的任何列。

這似乎是最簡單的方法來做到這一點,但也有許多其他方法。

希望這有助於!

0

這個宏是你的第一位 - 第二階段將非常相似。

您需要將5 s修改爲表格的長度。

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