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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值