Public Function MessageBox(Optional ByVal strPrompt As String, _
Optional ByVal vbButtons As VbMsgBoxStyle = vbMsgBoxHelpButton, _
Optional ByVal strTitle As String, _
Optional ByVal strHelpFile As String, _
Optional ByVal varContext, _
Optional ByVal lngKey As Long, _
Optional ByVal blnMessageBox As Boolean = True, _
Optional ByVal varReturnValue As Variant)
If blnMessageBox = False Then Exit Function
lngKey = Err.Number
If lngKey = 0 Then lngKey = CLng(vbButtons)
If strHelpFile = "" Then strHelpFile = ThisWorkbook.Path & "\Help.chm"
If IsMissing(varContext) Then varContext = 0
If Err.Number <> 0 Then
If strTitle = "" Then strTitle = "Loi he thong: " & Err.Number
strPrompt = "Khong thuc hien duoc vi:" & vbNewLine & _
"Lçi " & Err.Number & " - " & Err.Description
If vbButtons = vbMsgBoxHelpButton Then
vbButtons = vbCritical + vbMsgBoxHelpButton
Else
vbButtons = vbButtons + vbMsgBoxHelpButton
End If
Else
If strTitle = "" Then strTitle = "Thong bao!"
End If
Select Case vbButtons
Case vbMsgBoxHelpButton
vbButtons = vbInformation
Case vbYesNo, vbYesNoCancel, vbRetryCancel, vbAbortRetryIgnore
vbButtons = vbButtons + vbQuestion
Case vbOK
vbButtons = vbButtons + vbInformation
End Select
vbButtons = vbButtons + vbMsgBoxHelpButton
If IsMissing(varReturnValue) Then
MessageBox = MsgBox(strPrompt, vbButtons, strTitle, strHelpFile, varContext)
Else
MsgBox strPrompt, vbButtons, strTitle, strHelpFile, varContext
MessageBox = varReturnValue
End If
End Function
Private Sub cmbSave_Click()
Dim rgSoCT As Range [COLOR=darkgreen]' Cột chứng từ trong bảng kê[/COLOR]
Dim varSoCT As Variant [COLOR=darkgreen]' Số chứng từ cần kiểm tra (chưa biết kiểu dữ liệu)[/COLOR]
Dim blnExisted As Boolean [COLOR=darkgreen]' Chứng từ đã tồn tại[/COLOR]
Set rgSoCT = Sheets("BK").Range("sp")
varSoCT = Sheets("CT").Range("SoCT")
With WorksheetFunction
On Error GoTo SAVENOW:
blnExisted = Not .IsNA(.VLookup(varSoCT, rgSoCT, 1, 0))
If blnExisted Then
If MsgBox("Chung tu so " & varSoCT & " da ton tai. Ban van muon luu chung tu nay?", _
vbYesNo + vbQuestion + vbDefaultButton2, "Tim chung tu dang nhap") = vbNo Then Exit Sub
End If
SAVENOW:
[COLOR=darkgreen]'Tìm chứng từ đã có trong bảng kê chi tiết:[/COLOR]
Dim rgFounded As Range
Set rgFounded = rgSoCT.Find(varSoCT)
[COLOR=darkgreen]'Các xử lý lưu dữ liệu của bạn với rgFounded tìm được, ví dụ:[/COLOR]
MsgBox rgFounded.Address
[COLOR=darkgreen][COLOR=darkgreen]'...[/COLOR]
[/COLOR][COLOR=darkgreen]' Sau khi lưu xong, thông báo cho người dùng biết đã lưu thành công:[/COLOR]
MsgBox "Da luu chung tu so " & varSoCT & "!", vbInformation, "Luu chung tu"
End With
End Sub
kietmdc đã viết:Mình muốn xin các bạn 1 mả code để kiểm tra họ và tên trùng nhau trong cùng 1 lớp
Xin gui vế kietmdc@yahoo.com.vn
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 1
DIỄN ĐÀN GIẢI PHÁP EXCEL Group 2