如果所有单元都为零,请删除整个excel列(Delete entire excel column if all cells are zeroed)

Office IT屋
问 题

I'm a very beginner to excel and VBA (though I have some experience with VB.Net).
Having a large excel sheet with many columns, all with numerical values - how can I delete all the columns which have only zero values?

Thanks!

解决方案

Give this a try:

Sub ColumnKiller()
    Dim wf As WorksheetFunction
    Set wf = Application.WorksheetFunction
    Dim N As Long, L As Long
    ActiveSheet.UsedRange
    Set r = ActiveSheet.UsedRange
    nLastColumn = r.Columns.Count + r.Column - 1
    For L = nLastColumn To 1 Step -1
        If wf.Sum(Cells(1, L).EntireColumn) = 0 Then
            Cells(1, L).EntireColumn.Delete
        End If
    Next
End Sub

本文地址:IT屋 » Delete entire excel column if all cells are zeroed

问 题
我是一个非常初学者的excel和VBA(虽然我有一些VB.Net的经验)。

有一个大的excel表与许多列,所有数值 - 如何删除所有只有零值的列?



谢谢!


解决方案

尝试一下:



  Sub ColumnKiller()
Dim wf As WorksheetFunction
设置wf =应用程序.WorksheetFunction
Dim N As Long,L As Long
ActiveSheet.UsedRange
设置r = ActiveSheet.UsedRange
nLastColumn = r.Columns.Count + r.Column - 1
对于L = nLastColumn到1步-1
如果wf.Sum(Cells(1,L).EntireColumn)= 0然后
单元格(1,L).EntireColumn.Delete
结束如果
下一个
结束子

本文地址:IT屋 » 如果所有单元都为零,请删除整个excel列