我有一套相應的分類規則。基本上有3種規則,前兩種功能正確。以下代碼用於在規則中使用代碼的斜體部分。問題是第三套規則需要粗體和斜體部分。到目前爲止它不是,我不知道如何解決它。謝謝 :)。VB忽略規則的行
Option Explicit
Sub Tester()
Dim iCase As Long
Dim iLastName As Long
Dim iFirstName As Long
Dim iMedicalRecord As Long
Dim iGender As Long
Dim iPanel As Long
Dim iInheritance As Long
Dim iFuncrefGene As Long
Dim iExonicFuncrefGene As Long
Dim iPopFreqMax As Long
Dim iClinVar As Long
Dim iCommon As Long
Dim iClassification As Long
Dim vCase, vLastName, vFirstName, vMedicalRecord, vGender, vPanel, vInheritance
Dim vFuncrefGene, vExonicFuncrefGene, vPopFreqMax, vClinVar, vCommon, vClassification
Dim iRow As Long
Dim i As Long, rw As Range, rData As Range
Application.ScreenUpdating = False
'set the range
Set rData = Worksheets("annovar").Cells(4, 1).CurrentRegion
Set rw = rData.Rows(1)
'search row and define criteria
With Application.WorksheetFunction
iCase = .Match("Case", rData.Rows(1))
iLastName = .Match("Last Name", rData.Rows(1), 0)
iFirstName = .Match("First Name", rData.Rows(1), 0)
iMedicalRecord = .Match("Medical Record", rData.Rows(1), 0)
iGender = .Match("Gender", rData.Rows(1), 0)
iPanel = .Match("Panel", rData.Rows(1), 0)
iInheritance = .Match("Inheritance", rData.Rows(4), 0)
iPopFreqMax = .Match("PopFreqMax", rData.Rows(4), 0)
iClinVar = .Match("ClinVar", rData.Rows(4), 0)
iCommon = .Match("Common", rData.Rows(4), 0)
iFuncrefGene = .Match("Func.refGene", rData.Rows(4), 0)
iExonicFuncrefGene = .Match("ExonicFunc.refGene", rData.Rows(4), 0)
iClassification = .Match("Classification", rData.Rows(4), 0)
End With
' Classifications
For iRow = 2 To rData.Rows.Count ‘Start at line #2 to ignore the header row
Set rw = rData.Rows(iRow)
vCase = rw(iCase).Value
vLastName = rw(iLastName).Value
vFirstName = rw(iFirstName).Value
vMedicalRecord = rw(iMedicalRecord).Value
vGender = rw(iGender).Value
vPanel = rw(iPanel).Value
vInheritance = rw(iInheritance).Value
vPopFreqMax = rw(iPopFreqMax).Value
vClinVar = rw(iClinVar).Value
vCommon = rw(iCommon).Value
vFuncrefGene = rw(iFuncrefGene).Value
vExonicFuncrefGene = rw(iExonicFuncrefGene).Value
vClassification = 「」
‘pathogenic
Select Case vClinVar
Case 「pathogenic」
vClassification = 「pathogenic」
Case 「non-pathogenic」
vClassification = 「benign」
Case 「unknown」
vClassification = 「VUS」
Case 「untested」
vClassification = 「not provided」
End Select
If vInheritance = 「XL」 Or 「unknown」 Or 「sporadic, AD」 or 「de novo, AD」 Then vClassification = 「unknown」
If vClassification = 「」 And vClinVar = 「」 Then
If vInheritance = "AD" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
(.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon) = "") Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD" And _
.Cells(iRow, iPopFreqMax).Value >= 0.01) Or _
(.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value = "synonymous SNV" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
(.Cells(iRow, iClinVar).Value = "probable-non-pathogenic" And _
.Cells(iRow, iCommon) = "") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous SNV" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.01 And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD" And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "AR" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.1) Or _
(.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon) = "") Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AR" And _
.Cells(iRow, iPopFreqMax).Value >= 0.1) Or _
(.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.1 And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AR" And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "AD, AR" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD, AR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.1) Or _
(.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon) = "") Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD, AR" And _
.Cells(iRow, iPopFreqMax).Value >= 0.1) Or _
(.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD, AR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.1 And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If .Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "AD, AR" And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "XLD" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLD" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") Or _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLD" And _
.Cells(iRow, iGender).Value = "Male") Or _
.Cells(iRow, iGender).Value = "Female" And _
(.Cells(iRow, iPopFreqMax).Value >= 0.01) Or _
.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic" Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLD" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") Or _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLD" And _
.Cells(iRow, iGender).Value = "Male") Or _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "XLR for male" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Male" And _
(.Cells(iRow, iPopFreqMax).Value >= 0.01) Or _
.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.01 And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "XLR for female" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Female") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.02) Or _
.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value >= 0.02) Or _
(.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.02) And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Female") And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "XLD, XLR" And vGender = "Male" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.01) Or _
.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Male" And _
(.Cells(iRow, iPopFreqMax).Value >= 0.01) Or _
.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.01 And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Male") And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
If vInheritance = "XLD, XLR" And vGender = "Female" Then
' likely pathogenic
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Female") And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
(.Cells(iRow, iPopFreqMax).Value <= 0.02) Or _
.Cells(iRow, iClinVar).Value = "probable-pathogenic" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "likely pathogenic"
' likely benign
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value >= 0.02) Or _
(.Cells(iRow, iCommon).Value = "Common" Or _
.Cells(iRow, iClinVar).Value = "probable-non-pathogenic") Then _
.Cells(iRow, iClassification).Value = "likely benign"
' questionable
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iFuncrefGene).Value = "exonic" And _
.Cells(iRow, iExonicFuncrefGene).Value <> "synonymous" And _
.Cells(iRow, iGender).Value = "Female" And _
.Cells(iRow, iPopFreqMax).Value <> "" And _
.Cells(iRow, iPopFreqMax).Value <= 0.02) And _
.Cells(iRow, iCommon).Value = "Common" Then _
.Cells(iRow, iClassification).Value = "???"
' unknown
If (.Cells(iRow, iClinVar).Value = "" And _
.Cells(iRow, iInheritance).Value = "XLR" And _
.Cells(iRow, iGender).Value = "Female") And _
.Cells(iRow, iPopFreqMax).Value = "" And _
.Cells(iRow, iCommon).Value = "" Then _
.Cells(iRow, iClassification).Value = "unknown"
End If
‘ Populate classification value
rw(iClassification).Value = vClassification
Next iRow
目前還不清楚是什麼問題。第三套規則是什麼?現在,如果在預期的行中找不到任何這些術語,那麼您的代碼將引發運行時錯誤 - 是您想要的嗎? – 2015-02-06 00:42:54
完整的代碼現在已發佈。我會盡力解釋(希望更好),規則類別包括AD,AR,AD和AR,XLD,男性XLR,女性XLR和XL。前3個工作正常....這是X ...規則不起作用。我不知道爲什麼但是懷疑在Dim行中XG規則中使用了iGender,我認爲它被忽略了,我不知道如何包含它,而僅僅保留其他規則(仍然有效)。謝謝 :)。 – user3665765 2015-02-06 16:03:27