148btx
Thành viên mới

- Tham gia
- 14/10/06
- Bài viết
- 40
- Được thích
- 103
- Nghề nghiệp
- Thiết kế điện
Tôi kiếm được mã nguồn mở để sử dụng cho việc tìm kiếm từ ở tất cả các Sheets, nó hoạt động rất tốt nhưng đáng tiếc đây là MsgBox cho nên việc gõ từ tìm kiếm bằng chữ tiếng việt gặp trở ngại, chính vì vậy tôi muốn làm một UserForm để tìm kiếm từ trong tất cả các Sheet của một Workbook đang mở. Trong UserForm này bao gồm một TextBox để đánh từ cần tìm, một CommandButtonOK, một CommandButtonCancel,
Mong có bạn nào giúp tôi thực hiện công việc này:
Private Sub CommandButtonOk_Click()
?????????
If TextBox = "" Then
?????????
End Sub
Private Sub CommandButtonCancel_Click()
Me.Hide
End Sub
Đây là mã nguồn mở cho việc tìm kiếm bằng MsgBox:
Option Explicit
Public strSuch As String
Sub SearchAllSheets()
Dim wks As Worksheet
Dim rng As Range
Dim strAddress As String, strFind As String
strFind = InputBox("To enter the search criterion:", Application.UserName, strSuch)
If strFind = "" Then Exit Sub
For Each wks In Worksheets
Set rng = wks.Cells.Find(strFind, lookat:=xlPart, LookIn:=xlFormulas)
If Not rng Is Nothing Then
strAddress = rng.Address
Do
Application.Goto rng, False
If MsgBox("Next", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Set rng = Cells.FindNext(After:=ActiveCell)
If rng.Address = strAddress Then Exit Do
Loop
End If
Next wks
strSuch = strFind
MsgBox "No next source of information !", False, Application.UserName
Worksheets(1).Activate
Range("A1").Select
End Sub
Mong có bạn nào giúp tôi thực hiện công việc này:
Private Sub CommandButtonOk_Click()
?????????
If TextBox = "" Then
?????????
End Sub
Private Sub CommandButtonCancel_Click()
Me.Hide
End Sub
Đây là mã nguồn mở cho việc tìm kiếm bằng MsgBox:
Option Explicit
Public strSuch As String
Sub SearchAllSheets()
Dim wks As Worksheet
Dim rng As Range
Dim strAddress As String, strFind As String
strFind = InputBox("To enter the search criterion:", Application.UserName, strSuch)
If strFind = "" Then Exit Sub
For Each wks In Worksheets
Set rng = wks.Cells.Find(strFind, lookat:=xlPart, LookIn:=xlFormulas)
If Not rng Is Nothing Then
strAddress = rng.Address
Do
Application.Goto rng, False
If MsgBox("Next", vbYesNo + vbQuestion) = vbNo Then Exit Sub
Set rng = Cells.FindNext(After:=ActiveCell)
If rng.Address = strAddress Then Exit Do
Loop
End If
Next wks
strSuch = strFind
MsgBox "No next source of information !", False, Application.UserName
Worksheets(1).Activate
Range("A1").Select
End Sub