|
今天有空,给你做好了,窗口快捷键是CTRL+R,输完数据后按回车开始搜索
- Dim findData As String
- Dim firstResult As Range
- Dim result As Range
- Private Sub CommandButton1_Click()
- Set result = ActiveSheet.Range("G:K").FindPrevious(result)
- CommandButton2.Enabled = True
- result.Select
- If result.Address = firstResult.Address Then
- CommandButton1.Enabled = False
- CommandButton2.SetFocus
- End If
- End Sub
- Private Sub CommandButton2_Click()
- Set result = ActiveSheet.Range("G:K").FindNext(result)
- CommandButton1.Enabled = True
- result.Select
- If result.Address = firstResult.Address Then
- CommandButton2.Enabled = False
- CommandButton1.SetFocus
- End If
- End Sub
- Private Sub CommandButton3_Click()
- Call mark
- Unload Me
- End Sub
- Private Sub TextBox1_KeyDown(ByVal KeyCode As MSForms.ReturnInteger, ByVal Shift As Integer)
- If KeyCode = 13 Then
- findData = TextBox1.Text
- Call findvalue(TextBox1.Text)
- End If
- End Sub
- Private Sub findvalue(ByVal v As String)
- Set firstResult = ActiveSheet.Range("G:K").Find(v, , , 1)
- If firstResult Is Nothing Then
- TextBox1.Text = ""
-
- MsgBox "没有找到匹配金额,请输入下一个金额"
- TextBox1.SetFocus
- Else
- Set result = ActiveSheet.Range("G:K").FindNext(firstResult)
- If result Is Nothing Then
- firstResult.Select
- Me.Hide
- Call mark
- Unload Me
- Else
- firstResult.Select
- CommandButton2.Enabled = True
- Set result = firstResult
- End If
-
- End If
- End Sub
- Private Sub UserForm_Initialize()
- CommandButton1.Enabled = False
- CommandButton2.Enabled = False
- End Sub
- Sub mark()
- If MsgBox("此金额在表中位置为" & result.Address & ",是否标记该位置?", vbOKCancel) = vbOK Then
- Selection.Interior.Color = 65535
- End If
- End Sub
复制代码
|
|