VBA清空数据
'列数转字母
Function CNtoW(ByVal num As Long) As String
CNtoW = Replace(Cells(1, num).Address(False, False), "1", "")
End Function
'字母转列数
Function CWtoN(ByVal AB As String) As Long
CWtoN = Range("a1:" & AB & "1").Cells.Count
End Function
'search list if found return True, else return False
Function IsElementInDynamicList(element As String, list() As String) As Boolean
Dim i As Integer
For i = LBound(list) To UBound(list)
If list(i) = element Then
IsElementInDynamicList = True
Exit Function
End If
Next i
IsElementInDynamicList = False
End Function
'清空历史数据
Sub clear_new_sheet()
Application.ScreenUpdating = False
Dim row_max, start_row, col_max, end_col As Integer
row_max = ThisWorkbook.Sheets("new").Range("B65535").End(xlUp).Row
col_max = ThisWorkbook.Sheets("new").Range("IV1").End(xlToLeft).Column
'MsgBox "row_max:" & row_max
'MsgBox "col_max:" & col_max
For i = 1 To row_max
If ThisWorkbook.Sheets("new").Range("b" & i) = "编码" Then
start_row = i + 1
Exit For
End If
Next
For i = 1 To col_max
If ThisWorkbook.Sheets("new").Cells(1, i) = "是否新卡" Then
end_col = i
Exit For
End If
Next
col_string = CNtoW(end_col)
'清除历史残留
ThisWorkbook.Sheets("new").Select
If row_max >= start_row Then
Range("A" & start_row & ":" & col_string & row_max).Select
Selection.Delete
End If
Application.ScreenUpdating = True
End Sub