2015-02-05 99 views
0

我有一套相應的分類規則。基本上有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 
+0

目前還不清楚是什麼問題。第三套規則是什麼?現在,如果在預期的行中找不到任何這些術語,那麼您的代碼將引發運行時錯誤 - 是您想要的嗎? – 2015-02-06 00:42:54

+0

完整的代碼現在已發佈。我會盡力解釋(希望更好),規則類別包括AD,AR,AD和AR,XLD,男性XLR,女性XLR和XL。前3個工作正常....這是X ...規則不起作用。我不知道爲什麼但是懷疑在Dim行中XG規則中使用了iGender,我認爲它被忽略了,我不知道如何包含它,而僅僅保留其他規則(仍然有效)。謝謝 :)。 – user3665765 2015-02-06 16:03:27

回答

0

在您的問題中存在大量的代碼,並且可以通過不反覆測試相同的東西來大幅減少代碼。

我會開始使用實際變量的值,而不是每次都去表單:單單這樣做會顯着減少代碼量。

您也只需循環一次行 - 只需在每行上運行每個測試,直到獲得分類值。當你重複代碼時很難遵循,並且在任何編輯之後,錯誤的可能性都會顯着增加。

然後提出常見的測試 - 例如,前四個可以進入Select Case,一旦完成,不需要爲每個繼承值重複。

這裏是一個開始(只是一個骨架,因爲有太多對我來說因素一切歸因於一組核心)

Option Explicit '<<<< always use this at the tp of your modules 

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 

' AD 
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" Then vClassification = "unknown" 

    If vClassification = "" And vClinVar = "" Then 

     If vInheritance = "AD" Then 
      'do AD tests 

     End If 

     If vInheritance = "AR" Then 
      'do AR tests 

     End If 

     'etc etc 

    End If 

    'finally, populate the classification value (if any was allocated) 
    rw(iClassification).Value = vClassification 

    Next iRow 

End Sub 
+0

我修改了VB試圖按照你的例子,你能看看它(我是VB新手)。謝謝你的幫助 :)。 – user3665765 2015-02-09 19:21:48

+0

我會通過電子郵件發送給您一份工作簿的副本,是的,我確實使用了單詞......我不知道爲什麼我總是看起來如此。謝謝。 – user3665765 2015-02-10 14:29:57