I've been putzing around with this for awhile but I need to delete column B (minus the header) when ever it is empty. Does anyone have any idea on how to do this.


If xlWorkSheet.Range("B2:B65565").Value = "" Then
Dim rg As Excel.Range = xlWorkSheet.Columns("B")
rg.Select()
rg.Delete()

End If

Not the greatest way to remove the columns but hey it works for


Dim VerifyExcelColumnB As New ArrayList
For S As Integer = 2 To 65000


If xlWorkSheet.Range("B" & S).Value <> "" Then
VerifyExcelColumnB.Add(1)
End If

Next


If VerifyExcelColumnB.Count = 0 Then
Dim rg As Excel.Range

rg = xlWorkSheet.Range("B1", "C1")
rg.EntireColumn.Delete()

End If

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.