在导出到Access之前验证Excel

时间:2014-03-04 16:29:23

标签: sql excel vba ms-access

嘿,我已经编写了一个代码来验证excel表的所有行,然后我会错过一些点。这是代码

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",但OR语句没有良好的语法
  4. 谢谢

1 个答案:

答案 0 :(得分: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) <> "")