Sub Delete_blank_data()
Sheets("Statement").Select
'the column with blank rows is on the variable mycol
Dim mycol As String
mycol = Range("E51").Value
Columns(mycol & ":" & mycol).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
答案 0 :(得分:1)
Sub Delete_blank_data()
' Sheets("Statement").Select
'the column with blank rows is on the variable mycol
Dim mycol As String
mycol = Range("E51").Value ' the value has to be between A to Z
' mycol = "A"
If mycol <> "" And Len(mycol) <> 1 Then
MsgBox "Invalid column Value provided", vbInformation
Exit Sub
End If
Columns(mycol & ":" & mycol).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End Sub
使用索引编号
Sub Delete_blank_data_index()
On Error Resume Next
Sheets("Statement").Select
'the column with blank rows is on the variable mycol
Dim mycol As Range
Set mycol = Range("E51")
If Not mycol Is Nothing And mycol.Value <> "" And IsNumeric(mycol.Value) Then
If CInt(mycol.Value) > 0 Then
Columns(CInt(mycol)).SpecialCells(xlCellTypeBlanks).EntireRow.Delete
End If
End If
End Sub