2014-03-04 85 views
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 
  1. 在每一個IF結束,如果是真的,我想退出類似If Cells(c, 3) = "" Then errTxt = "Missing Ticket Number" Then Exit Do但2次,然後不工作
  2. 在結束時,如果沒有錯誤設置errTxt爲「已處理」
  3. 我想測試If Cells(c, 13) <> Or("Y","N","") Then errTxt = "Wrong OATS"但或聲明不會有良好的語法

謝謝

回答

0

1.

If Cells(c, 3) = "" Then 
    errTxt = "Missing Ticket Number" 
    Exit Do 
End If 

2.

If varTxt = "" Then 
    errTxt = "Processed" 
    Exit Do 
End If 

3.

Cells(c, 13) <> "Y" And Cells(c, 13) <> "N" And Cells(c, 13) <> "")