Vba 如何将最近编辑过单元格的行移到底部?

Vba 如何将最近编辑过单元格的行移到底部?,vba,excel,userform,Vba,Excel,Userform,到目前为止,我有一个excel表格,其中显示了有关零件的信息,在“H”列中有一个初始列,当有人在该列中输入首字母时,表示零件已完成。带有新首字母的行应位于数据的底部。但是,在此之前,我已经设置了一个userform“UserForm2”,用户将在其中输入密码。所以,如果我能得到一些指导,当他们按下“确定按钮”时,我该如何去做,那将是令人惊讶的 编辑:我试着用工作表更改事件将其向下移动,但我不知道如何使其工作 Edit2(不存在):我已经找到了答案;但是,我在下面添加的代码给了我一个无效的限定符错

到目前为止,我有一个excel表格,其中显示了有关零件的信息,在“H”列中有一个初始列,当有人在该列中输入首字母时,表示零件已完成。带有新首字母的行应位于数据的底部。但是,在此之前,我已经设置了一个userform“UserForm2”,用户将在其中输入密码。所以,如果我能得到一些指导,当他们按下“确定按钮”时,我该如何去做,那将是令人惊讶的

编辑:我试着用工作表更改事件将其向下移动,但我不知道如何使其工作

Edit2(不存在):我已经找到了答案;但是,我在下面添加的代码给了我一个无效的限定符错误

Edit3:有些进步!下面新修改的代码做了我现在想做的事情;然而“userform2”在被复制到底部后不断弹出,我不完全确定为什么以及是否有人会碰巧知道如何修复它,并告诉我这将非常感谢

编辑4:它有效!。。。大部分情况下。上一次编辑中的错误仍在弹出。同样,更新的代码如下所示

用户表单2:

    Private Sub CancelButton_Click()
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        Unload Me
    End Sub
    Private Sub OkayButton_Click()
        IniPass = "pass"
        If Me.PasswordIn.Value = IniPass Then
            Unload Me
        Else
            MsgBox "Incorrect Password"
        End If
    End Sub
    Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
        If CloseMode = vbFormControlMenu Then
            Cancel = True
            MsgBox "Please use the Cancel button to close the password window!"
        End If
    End Sub
第1页(查阅):


Userform2可能会弹出,因为这
如果不相交(目标,范围(“H:H”))什么都不是,那么
总是计算为true。传递到工作表更改中的范围是否始终包含“H”?

感谢您的回复。TL;博士:是的。员工将在该列中输入其姓名首字母,表示该部分已完成,在输入密码后,该行应移到表的末尾。因此,如果“H:H”始终在目标范围内,intersect将永远不会返回
nothing
,并且您的条件将始终为true,这将导致始终调用
show
例程。除非我误会了什么,对吧。我不知道我该怎么解决这个问题,有什么建议吗?
Private Sub Worksheet_Change(ByVal Target As Range)

    LooupValue = Target.Value
    part = Application.VLookup(LooupValue, MasterSheet.Range("A:AO"), 7, False)
    desc = Application.VLookup(LooupValue, MasterSheet.Range("A:AO"), 9, False)
    cust = Application.VLookup(LooupValue, MasterSheet.Range("A:AO"), 10, False)
    due = Application.VLookup(LooupValue, MasterSheet.Range("A:AO"), 13, False)

    If Not Application.Intersect(Range("A:A"), Target) Is Nothing Then
        Range(Target.Address).Offset(0, 3).Value = part
        Range(Target.Address).Offset(0, 4).Value = desc
        Range(Target.Address).Offset(0, 5).Value = cust
        Range(Target.Address).Offset(0, 6).Value = due
    End If

    If Not Intersect(Target, Range("H:H")) Is Nothing Then
        UserForm2.Show
        Application.EnableEvents = False
        lastRow = Cells(Rows.Count, "A").End(xlUp).Row
        Sheet1.Rows(Target.Row).Cut Sheet1.Rows(lastRow).Offset(1, 0)
        Application.EnableEvents = True
        Application.CutCopyMode = False
        On Error Resume Next
            Range("A:A").SpecialCells(xlCellTypeBlanks).EntireRow.Delete
    End If

End Sub