2015-02-05 98 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