0
嘿,我已經寫了一個代碼來驗證excel表格的所有行,然後我就錯過了一些要點。下面是代碼驗證Excel導出到Access之前
Sub Validation_Trades()
Dim varTxt As String
Dim errTxt As String
Dim WS As Worksheet
Dim c As Long
Set WS = Worksheets("Trades")
c = 2
Do
varTxt = WS.Range("A" & CStr(c)).Value
errTxt = WS.Range("AP" & CStr(c)).Value
If varTxt = "" Then Exit Do
If Cells(c, 3) = "" Then errTxt = "Missing Ticket Number"
If Cells(c, 4) = "" Then errTxt = "Missing BRKR1"
If Cells(c, 5) = "" Then errTxt = "Missing BRKR2"
If Cells(c, 6) = "" Then errTxt = "Missing Trade Date"
If Cells(c, 7) = "" Then errTxt = "Missing Rec Time"
If Cells(c, 8).Value < Cells(c, 7).Value Then errTxt = "Wrong Sent Time"
If Cells(c, 9) = "" Then errTxt = "Missing Exec Time"
If Cells(c, 10) = "" Then errTxt = "Missing Cust Short Code"
If Cells(c, 12) = "" Then errTxt = "Missing Trader Initial"
c = c + 1
Loop
End Sub
- 在每一個IF結束,如果是真的,我想退出類似
If Cells(c, 3) = "" Then errTxt = "Missing Ticket Number" Then Exit Do
但2次,然後不工作 - 在結束時,如果沒有錯誤設置errTxt爲「已處理」
- 我想測試
If Cells(c, 13) <> Or("Y","N","") Then errTxt = "Wrong OATS"
但或聲明不會有良好的語法
謝謝