到目前为止,我有一个excel工作表,用于显示有关零件的信息,并且在“ H”列中有一个初始列,当有人将姓名缩写放在该列中时,表明该零件已完成。带有新首字母的行应转到数据的底部。但是,在发生这种情况之前,我已经设置了一个用户窗体“ 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
答案 0 :(得分:0)
Userform2可能会弹出,因为此If Not Intersect(Target, Range("H:H")) Is Nothing Then
总是评估为true。传递到工作表更改的范围是否始终包含“ H”?