需要帮助遍历唯一ID-VBA

时间:2018-12-07 16:36:06

标签: excel vba

按钮激活此子查询包含与文档关联的唯一ID的行,并删除该记录行。 如果找不到唯一ID,我想请用户“尝试输入另一个值”。

输入大数字时出现溢出错误。

预先感谢您的帮助。

Sub deleteRecord()

Sheets("Archive Log").Unprotect

Dim valuee As Integer
Dim x As Variant

Do While x = False

    'Taking the input value
    valuee = InputBox("What is the unique ID number of the file you wish to delete from the archive?")
    Do While valuee > 99999
        valuee = InputBox("Try entering another value")
        Loop

    'Creating variables for our loop
    Dim i As Long, current As Long
    Dim ThisCell As Variant

    'Loop through unique ID column to find a value that matches the input value
    'Then delete that row from column 1 to 13 and shift the cells up
    For i = 1 To Rows.Count
        If Cells(i, 1).value = valuee Then
            x = True
            Range(Cells(i, 1), Cells(i, 13)).Delete Shift:=xlUp
            Exit For
        End If

    Next i

Loop

Sheets("Archive Log").Protect

End Sub

0 个答案:

没有答案