如圖一VBA表單內的A、B、C、D、E、F文本框內輸入字符,再點擊核對時自動把里面的輸入的內容自動保存到圖二作業簿對應的欄位,并且自動生成輸入時間,如果其中任意一欄未填寫內容,則提示核對核對失敗,反之提示核對成功。


uj5u.com熱心網友回復:
Public Function checks() As Boolean
Dim strA As String, strB As String, strC As String
'紅色:
strA = Trim(txtA.Text)
strB = Left$(Trim(txtF.Text), Len(strA))
strC = Mid(Trim(txtC.Text), Len(Trim(txtD.Text)) + 2, Len(strA))
checks = strA = strB And strA = strC
If checks = False Then
Exit Function
End If
'藍色:
strA = Trim(txtD.Text)
strB = Trim(txtE.Text)
strC = Mid(Trim(txtC.Text), 1, Len(strA))
checks = strA = strB And strA = strC
End Function
Private Function insToXls() As Boolean
Dim index As Integer, inx As Integer
index = Cells(Rows.Count, 1).End(xlUp).row '找到末行
inx = Val(Range("A" & index)) + 1 '末行序號+1
Dim arr As Variant
arr = Array(inx, txtA.Text, txtB.Text, txtC.Text, txtD.Text, txtE.Text, txtF.Text, Now())
Range("A" & index + 1, "H" & index + 1) = arr
End Function
Private Sub cmd_Click()
If checks() Then
MsgBox "比對成功!", vbOKOnly, "比對結果"
insToXls
Else
MsgBox "比對失敗!", vbOKOnly, "比對結果"
End If
End Sub
uj5u.com熱心網友回復:
[face]emoji:010.png[/face]回錯帖子了!轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/285014.html
標籤:VBA
上一篇:二進制檔案怎么看啊?