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

问题描述 投票:0回答:1

到目前为止,我有一个显示有关零件信息的Excel工作表,在“H”列中有一个初始列,当有人将其首字母放入该列时,它表示该零件已完成。具有新首字母的行应该到数据的底部。但是,在此之前,我已经设置了一个userform,'UserForm2',用户将在其中输入密码。所以,如果我按下'OkayButton'就可以得到一些关于如何去做的指导,那就太棒了!

编辑:我尝试使用工作表更改事件将其移除,但我无法弄清楚如何使其工作。

Edit2(已解散):我有点想通了;但是,我在下面添加的代码我添加了一个无效的限定符错误。

Edit3:有些进步!下面新更改的代码完成了我现在的工作;然而,'userform2'在复制到底部后不断弹出,我不完全确定为什么,如果有人碰巧知道如何修复它,可以告诉我,我会非常感激!

Edit4:它有效!...大部分时间。上一次编辑中的错误仍然会弹出。同样,更新的代码如下。

UserForm2:

    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

工作表Sheet1(查找):

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
excel vba excel-vba userform
1个回答
0
投票

Userform2可能会弹出,因为这个If Not Intersect(Target, Range("H:H")) Is Nothing Then总是评估为true。传入工作表更改的范围是否始终包含“H”?

© www.soinside.com 2019 - 2024. All rights reserved.