tuananhya2
Thành viên mới

- Tham gia
- 18/8/12
- Bài viết
- 8
- Được thích
- 0
Co ai chỉ dùm cách tạo pass marco với
Private Function MSTcheck(ByVal mst1) As Boolean
Dim msttext, skt, mst As String
If mst1 = "" Then
msttext = msttext
End If
If Len(mst1 & "") = 13 Or Len(mst1 & "") = 14 Or Len(mst1 & "") = 10 Then
mst = Mid(mst1, 1, 10)
If IsNumeric(mst) Then
msttext = mst
Else
Exit Function
End If
msttext = mst
skt = CDbl(Mid(msttext, 1, 1)) * 31
skt = skt + CDbl(Mid(msttext, 2, 1)) * 29
skt = skt + CDbl(Mid(msttext, 3, 1)) * 23
skt = skt + CDbl(Mid(msttext, 4, 1)) * 19
skt = skt + CDbl(Mid(msttext, 5, 1)) * 17
skt = skt + CDbl(Mid(msttext, 6, 1)) * 13
skt = skt + CDbl(Mid(msttext, 7, 1)) * 7
skt = skt + CDbl(Mid(msttext, 8, 1)) * 5
skt = skt + CDbl(Mid(msttext, 9, 1)) * 3
MSTcheck = (CDbl(Mid(msttext, 10)) = 10 - skt Mod 11)
End If
End Function
Sub ToMau_Cot_H()
Dim i As Long
Dim arrRes, arrSrc, rng As Range
Dim bChk As Boolean
[A18:O2000].Font.ColorIndex = 1
[A18:O2000].Interior.ColorIndex = xlNone
[A18:O2000].Font.Bold = 0
Set rng = Range([A18], [A65536].End(3)).Resize(, 15)
arrSrc = rng.Value
For i = 1 To UBound(arrSrc, 1)
If arrSrc(i, 1) <> "" Then
bChk =[COLOR=#ff0000][B] MSTcheck[/B][/COLOR](CStr(arrSrc(i, 8)))
If bChk = False Then rng(i, 8).Font.ColorIndex = 3
End If
Next i
End Sub
Giúp sửa code kiểm tra Mã số thuế, nếu sai thì tô màu
------------------------------------------------------------------
Em muốn kiểm tra Mã số thuế ở cột G, nếu sai thì tô màu chữ, đúng thì kg tô màu!
Hàm Kiểm tra Mã số thuế
Code để tô màuMã:Private Function MSTcheck(ByVal mst1) As Boolean Dim msttext, skt, mst As String If mst1 = "" Then msttext = msttext End If If Len(mst1 & "") = 13 Or Len(mst1 & "") = 14 Or Len(mst1 & "") = 10 Then mst = Mid(mst1, 1, 10) If IsNumeric(mst) Then msttext = mst Else Exit Function End If msttext = mst skt = CDbl(Mid(msttext, 1, 1)) * 31 skt = skt + CDbl(Mid(msttext, 2, 1)) * 29 skt = skt + CDbl(Mid(msttext, 3, 1)) * 23 skt = skt + CDbl(Mid(msttext, 4, 1)) * 19 skt = skt + CDbl(Mid(msttext, 5, 1)) * 17 skt = skt + CDbl(Mid(msttext, 6, 1)) * 13 skt = skt + CDbl(Mid(msttext, 7, 1)) * 7 skt = skt + CDbl(Mid(msttext, 8, 1)) * 5 skt = skt + CDbl(Mid(msttext, 9, 1)) * 3 MSTcheck = (CDbl(Mid(msttext, 10)) = 10 - skt Mod 11) End If End Function
Code trên bị báo lỗi ở MSTcheckMã:Sub ToMau_Cot_H() Dim i As Long Dim arrRes, arrSrc, rng As Range Dim bChk As Boolean [A18:O2000].Font.ColorIndex = 1 [A18:O2000].Interior.ColorIndex = xlNone [A18:O2000].Font.Bold = 0 Set rng = Range([A18], [A65536].End(3)).Resize(, 15) arrSrc = rng.Value For i = 1 To UBound(arrSrc, 1) If arrSrc(i, 1) <> "" Then bChk =[COLOR=#ff0000][B] MSTcheck[/B][/COLOR](CStr(arrSrc(i, 8))) If bChk = False Then rng(i, 8).Font.ColorIndex = 3 End If Next i End Sub
và lỗi là " Compile error: Sub or fuction not difined "
Em sửa hòai mấy giờ rồi nhưng vẫn chưa được!
Thầy cô & anh chị giúp em!
Em cảm ơn!
Sub TestMau_CotE()
Dim i As Long
Dim arrRes, arrSrc, rng As Range
[A18:O2000].Font.ColorIndex = 1
Set rng = Range([A18], [A65536].End(3)).Resize(, 15)
arrSrc = rng.Value
For i = 1 To UBound(arrSrc, 1)
If Val(arrSrc(i, 5)) = False Then rng(i, 5).Font.ColorIndex = 3
Next
End Sub
Để đơn giản hóa vấn đề, ta lấy thằng arrSrc(i, 5) nhân với 1, nếu báo lỗi (tức Err.Number >0) thì tô màuGIÚP SỬA CODE TÔ MÀU!
-------------------------------
Em có viết code tô màu cho cột E như sau:
Cột E này được phép nhập kiểu Number (ví dụ: 301) hoặc kiểu chuỗi, nhưng không được có ký tự là chữ lẫn lộn vào , ví dụ:
'0000301 -> OK
a301 -> không được
30ab1 ->không được
301dg -> không được
-----------
Code em như sau
Nhưng trong File của em, cell E24 & E30 không bị tô màu?Mã:Sub TestMau_CotE() Dim i As Long Dim arrRes, arrSrc, rng As Range [A18:O2000].Font.ColorIndex = 1 Set rng = Range([A18], [A65536].End(3)).Resize(, 15) arrSrc = rng.Value For i = 1 To UBound(arrSrc, 1) If Val(arrSrc(i, 5)) = False Then rng(i, 5).Font.ColorIndex = 3 Next End Sub
Em không biết fải sửa Val thành cái gì?
Em cảm ơn!
Sub TestMau_CotE()
Dim i As Long, tmp
Dim arrRes, arrSrc, rng As Range
[COLOR=#ff0000]On Error Resume Next[/COLOR]
[A18:O2000].Font.ColorIndex = 1
Set rng = Range([A18], [A65536].End(3)).Resize(, 15)
arrSrc = rng.Value
For i = 1 To UBound(arrSrc, 1)
tmp = arrSrc(i, 5) * 1
[COLOR=#ff0000]If Err.Number Then
rng(i, 5).Font.ColorIndex = 3
Err.Clear
End If[/COLOR]
Next
End Sub
Sub TestMau_CotE()
Dim i As Long
Dim arrRes, arrSrc, rng As Range
[A18:O2000].Font.ColorIndex = 1
Set rng = Range([A18], [A65536].End(3)).Resize(, 15)
arrSrc = rng.Value
For i = 1 To UBound(arrSrc, 1)
[COLOR=#ff0000]If Not IsNumeric(arrSrc(i, 5)) Then[/COLOR] rng(i, 5).Font.ColorIndex = 3
Next
End Sub
Cho em hỏi thêm, có hàm nào kiểm tra cell là số nguyên dương không ạ!
Em cảm ơn!
If IsNumeric(Số) then ''<--- Kiểm tra xem có phải là số không
If Số > 0 then ''<--- Kiểm tra xem số có dương không?
If Int(Số) = Số then ''<--- Kiểm tra xem số có nguyên không
Chắc đại loại là thế này. Giả sử pass của bạn là 123456789
PHP:Sub mo_file() Dim pass pass = Application.InputBox("Nhap Pass:") If pass <> 123456789 Then Exit Sub Workbooks.Open duongdantenfile, , , , pass End Sub
ActiveWorkbook.UpdateLink Name:=ActiveWorkbook.LinkSources
Dim Pass
Pass = Application.InputBox("Xin vui lòng nhâp Password:")
If Pass = ("123") Then
End If
End Sub
Xin chào mọi người.
Em có đoạn code này:
Sub BackupFiles()
HTML:Dim Pass Pass = Application.InputBox("Xin vui lòng nhâp Password:") If Pass = ("123") Then End If End Sub
Xin hỏi có cách nào khi nhập 123 đấy nó hiển thị thành dấu * như password không?
Ví dụ như hình ảnh:
Theo code của Em thì nó thế này:View attachment 96940
Xin hỏi phải viết code thế nào để nó thành thế này được ạ:View attachment 96941
Mong các chuyên gia giúp đỡ. Xin cám ơn!
Theo mình biết thì không thể được đâu.
Function PassInputBox(Prompt As String, Optional PasswordChar As String, Optional Title As String, Optional Default As String, Optional XPos As Long, Optional YPos As Long)
Dim UF 'Store the VBComponent
Dim VUF As Object 'Store the userform object
Dim Lb As Object 'Label for the Prompt
Dim Tb As Object 'TextBox which holds the password
Dim BOk As Object
Dim BCancel As Object
Dim VBAVisible As Boolean 'Store VBE.Mainwindow visible state to restore it
Dim i As Integer
'Default Title is the same as InputBox
If Len(Title) = 0 Then Title = Application.Name
'Store the visible property of the VBE mainwindow and hide it to prevent screen flashing
VBAVisible = Application.VBE.MainWindow.Visible
Application.VBE.MainWindow.Visible = False
'Add temporary Userform
Set UF = ThisWorkbook.VBProject.VBComponents.Add(3)
'Add the textbox. If no PasswordChar was supplied, the text will appear normally
Set Tb = UF.Designer.Controls.Add("Forms.Textbox.1", "TextBox1")
With Tb
.PasswordChar = PasswordChar
.Left = 4.5
.Top = 69.75
.Width = 254.25
.Height = 15.75
.Value = Default
End With
'Add the prompt
Set Lb = UF.Designer.Controls.Add("Forms.Label.1")
With Lb
.Caption = Prompt
.WordWrap = True
.Left = 6.75
.Top = 6.75
.Width = 198
.Height = 54
End With
'Button OK, it is the default button
Set BOk = UF.Designer.Controls.Add("Forms.CommandButton.1", "BOk")
With BOk
.Caption = "OK"
.Left = 209.25
.Top = 4.5
.Width = 49.5
.Height = 18
.Default = True
End With
'Button Cancel
Set BCancel = UF.Designer.Controls.Add("Forms.CommandButton.1", "BCancel")
With BCancel
.Caption = "Cancel"
.Cancel = True
.Left = 209.25
.Top = 27
.Width = 49.5
.Height = 18
End With
'Add code to the Userform module
With UF.CodeModule
i = .CountOfLines
'MyText is a variant which will hold the answer the user pressed
.InsertLines i + 0, "Public MyText as Variant"
'Pressed Cancel, so assign False to MyText
.InsertLines i + 1, "Private Sub BCancel_Click()"
.InsertLines i + 2, " MyText = False: Me.Hide"
.InsertLines i + 3, "End Sub"
'Pressed Ok, so assign the value of TextBox1 to MyText
.InsertLines i + 4, "Private Sub BOk_Click()"
.InsertLines i + 5, " MyText = TextBox1.Value: Me.Hide"
.InsertLines i + 6, "End Sub"
'Closing the form using "X", so assign False to MyText
.InsertLines i + 7, "Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)"
.InsertLines i + 8, " If CloseMode = 0 Then Cancel = True: MyText = False: Me.Hide"
.InsertLines i + 9, "End Sub"
End With
'Properties for the userform
With UF
.Properties("Caption") = Title
.Properties("Width") = 273
.Properties("Height") = 108.75
'Center on screen or show in a specific position
If XPos > 0 Or YPos > 0 Then
.Properties("StartUpPosition") = 0
.Properties("Left") = XPos
.Properties("Top") = YPos
Else
.Properties("StartUpPosition") = 1
End If
End With
'Include the UF in the Userforms collection
Set VUF = VBA.UserForms.Add(UF.Name)
'Show the Userform
VUF.Show
'Pass the result to this function
PassInputBox = VUF.MyText
'Remove the VBcomponet
ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=UF
'Restore the VBE Mainwindow
Application.VBE.MainWindow.Visible = VBAVisible
End Function
Sub Test()
Dim ans As Variant 'ans is declared Variant to work similar to Application.InputBox
Dim App As PwdInputBox 'Reference the class module
Set App = New PwdInputBox 'Create a new instance
ans = App.PassInputBox("Please enter the password", "*", "My Application") 'Show the Inputbox and store the result
If ans = False Then
MsgBox "Pressed Cancel"
Else
MsgBox "The password entered is: " & ans
End If
End Sub
Với trinh độ mình thì không được nhưng với người khác em nghĩ là không gì là không thể
Bạn code thể tham khảo file sau
Website: MrExcel
Với trinh độ mình thì không được nhưng với người khác em nghĩ là không gì là không thể
Dùng inputbox thì có thể không được nhưng nếu tạo 1 userform có textbox trong đó thì có thể làm được thông qua thuộc tính passwordchar của textbox.
Với trinh độ mình thì không được nhưng với người khác em nghĩ là không gì là không thể
Code trong Classmodule
PHP:Function PassInputBox(Prompt As String, Optional PasswordChar As String, Optional Title As String, Optional Default As String, Optional XPos As Long, Optional YPos As Long) Dim UF 'Store the VBComponent Dim VUF As Object 'Store the userform object Dim Lb As Object 'Label for the Prompt Dim Tb As Object 'TextBox which holds the password Dim BOk As Object Dim BCancel As Object Dim VBAVisible As Boolean 'Store VBE.Mainwindow visible state to restore it Dim i As Integer 'Default Title is the same as InputBox If Len(Title) = 0 Then Title = Application.Name 'Store the visible property of the VBE mainwindow and hide it to prevent screen flashing VBAVisible = Application.VBE.MainWindow.Visible Application.VBE.MainWindow.Visible = False 'Add temporary Userform Set UF = ThisWorkbook.VBProject.VBComponents.Add(3) 'Add the textbox. If no PasswordChar was supplied, the text will appear normally Set Tb = UF.Designer.Controls.Add("Forms.Textbox.1", "TextBox1") With Tb .PasswordChar = PasswordChar .Left = 4.5 .Top = 69.75 .Width = 254.25 .Height = 15.75 .Value = Default End With 'Add the prompt Set Lb = UF.Designer.Controls.Add("Forms.Label.1") With Lb .Caption = Prompt .WordWrap = True .Left = 6.75 .Top = 6.75 .Width = 198 .Height = 54 End With 'Button OK, it is the default button Set BOk = UF.Designer.Controls.Add("Forms.CommandButton.1", "BOk") With BOk .Caption = "OK" .Left = 209.25 .Top = 4.5 .Width = 49.5 .Height = 18 .Default = True End With 'Button Cancel Set BCancel = UF.Designer.Controls.Add("Forms.CommandButton.1", "BCancel") With BCancel .Caption = "Cancel" .Cancel = True .Left = 209.25 .Top = 27 .Width = 49.5 .Height = 18 End With 'Add code to the Userform module With UF.CodeModule i = .CountOfLines 'MyText is a variant which will hold the answer the user pressed .InsertLines i + 0, "Public MyText as Variant" 'Pressed Cancel, so assign False to MyText .InsertLines i + 1, "Private Sub BCancel_Click()" .InsertLines i + 2, " MyText = False: Me.Hide" .InsertLines i + 3, "End Sub" 'Pressed Ok, so assign the value of TextBox1 to MyText .InsertLines i + 4, "Private Sub BOk_Click()" .InsertLines i + 5, " MyText = TextBox1.Value: Me.Hide" .InsertLines i + 6, "End Sub" 'Closing the form using "X", so assign False to MyText .InsertLines i + 7, "Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)" .InsertLines i + 8, " If CloseMode = 0 Then Cancel = True: MyText = False: Me.Hide" .InsertLines i + 9, "End Sub" End With 'Properties for the userform With UF .Properties("Caption") = Title .Properties("Width") = 273 .Properties("Height") = 108.75 'Center on screen or show in a specific position If XPos > 0 Or YPos > 0 Then .Properties("StartUpPosition") = 0 .Properties("Left") = XPos .Properties("Top") = YPos Else .Properties("StartUpPosition") = 1 End If End With 'Include the UF in the Userforms collection Set VUF = VBA.UserForms.Add(UF.Name) 'Show the Userform VUF.Show 'Pass the result to this function PassInputBox = VUF.MyText 'Remove the VBcomponet ThisWorkbook.VBProject.VBComponents.Remove VBComponent:=UF 'Restore the VBE Mainwindow Application.VBE.MainWindow.Visible = VBAVisible End Function
Code trong Module
PHP:Sub Test() Dim ans As Variant 'ans is declared Variant to work similar to Application.InputBox Dim App As PwdInputBox 'Reference the class module Set App = New PwdInputBox 'Create a new instance ans = App.PassInputBox("Please enter the password", "*", "My Application") 'Show the Inputbox and store the result If ans = False Then MsgBox "Pressed Cancel" Else MsgBox "The password entered is: " & ans End If End Sub
Bạn code thể tham khảo file sau
Website: MrExcel
Phiền GPE có thể cho em 1 ví dụ đính kèm đơn giản được không ạ?
Quan trọng câu thông báo lỗi là gì?Em vừa chạy phát báo lỗi luôn ??
Phải xử lý thế nào ạ?
Tiếp tục thử xem saoEm biết Chỗ Thầy chỉ rồi.
Nhưng code fai viết theo cấu trúc kểu gì ạ,
ví dụ pass là:123
Nếu pass đúng thì sẽ thực hiện yêu cầu.
Nếu sai pass exit sub.
Thầy cho em 1 ví dụ (đoạn code) gán điều kiện code vào bài này với ạ.