循环有一个做,但程序说,没有

对于我正在编写的一段代码,我有一个简单而令人愤怒的问题。 无论出于何种原因,它坚持说,尽pipe明确地处于顶端,我仍然没有为我的循环做好准备。 也许我在写if语句的时候做了一些事情,但是我不这么认为。 如果你能看到它,帮助我,这将是伟大的。 大部分的代码是一堆If,那么,GoTo语句就可以随意浏览它。

Do While Cells(i, "B").Value <> "" 'X Block If Cells(i, "B").Value = "U" Then GoTo U1: ElseIf Cells(i, "B").Value = "C" Then GoTo C1: ElseIf Cells(i, "B").Value = "A" Then GoTo A1: ElseIf Cells(i, "B").Value = "G" Then GoTo G1: End If 'UX Block U1: If Cells(i + 1, "B").Value = "U" Then GoTo UU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo UC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo UA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo UG2: End If 'UUX Block UU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Phe" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Leu" End If GoTo EndOfAcids: 'UCX Block UC2: Cells(a, "C").Value = "Ser" GoTo EndOfAcids: 'UAX Block UA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Tyr" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Stop Codon" End If GoTo EndOfAcids: 'UGX Block UG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Cys" ElseIf Cells(i + 2, "B").Value = "A" Then Cells(a, "C").Value = "Stop Codon" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Trp" End If GoTo EndOfAcids: 'CX Block C1: If Cells(i + 1, "B").Value = "U" Then GoTo CU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo CC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo CA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo CG2: End If 'CUX Block CU2: Cells(a, "C").Value = "Leu" GoTo EndOfAcids: 'CCX Block CC2: Cells(a, "C").Value = "Pro" GoTo EndOfAcids: 'CAX Block CA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "His" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Gln" End If GoTo EndOfAcids: 'CGX Block CG2: Cells(a, "C").Value = "Arg" GoTo EndOfAcids: 'AX Block A1: If Cells(i + 1, "B").Value = "U" Then GoTo AU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo AC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo AA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo AG2: End If 'AUX Block AU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Or Cells(i + 2).Value = "A" Then Cells(a, "C").Value = "Ile" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Met" End If GoTo EndOfAcids: 'ACX Block AC2: Cells(a, "C").Value = "Thr" GoTo EndOfAcids: 'AAX Block AA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asn" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Lys" End If GoTo EndOfAcids: 'AGX Block AG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Ser" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Arg" End If GoTo EndOfAcids: 'GX Block G1: If Cells(i + 1, "B").Value = "U" Then GoTo GU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo GC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo GA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo GG2: End If 'GUX Block GU2: Cells(a, "C").Value = "Val" GoTo EndOfAcids: 'GCX Block GC2: Cells(a, "C").Value = "Ala" GoTo EndOfAcids: 'GAX Block GA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asp" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Glu" GoTo EndOfAcids: 'GGX Block GG2: Cells(a, "C").Value = "Gly" GoTo EndOfAcids: EndOfAcids: i = i + 3 a = a + 1 Loop End Sub 

所以do是代码的顶部,但是当我运行它时,程序说没有办法。 不知道为什么。 任何帮助,将不胜感激。 有更多的代码,所以我会发布下面的整体,但问题循环是上面张贴的东西。

 Option Explicit Sub RNATrascription() Dim i As Long Dim a As Long i = 2 a = 2 Do While Cells(i, "A").Value <> "" If Cells(i, "A").Value = "A" Or Cells(i, "A").Value = "a" Then Cells(i, "B").Value = "U" ElseIf Cells(i, "A").Value = "T" Or Cells(i, "A").Value = "t" Then Cells(i, "B").Value = "A" ElseIf Cells(i, "A") = "G" Or Cells(i, "A").Value = "g" Then Cells(i, "B") = "C" ElseIf Cells(i, "A") = "C" Or Cells(i, "A").Value = "c" Then Cells(i, "B") = "G" ElseIf Cells(i, "A") <> "A" Or Cells(i, "A") <> "a" Or Cells(i, "A") <> "T" Or Cells(i, "A") <> "t" Or Cells(i, "A") <> "G" Or Cells(i, "A") <> "g" Or Cells(i, "A") <> "C" Or Cells(i, "A") <> "c" Then MsgBox "You have mis typed your DNA sequence" End If i = i + 1 Loop Do While Cells(i, "B").Value <> "" 'X Block If Cells(i, "B").Value = "U" Then GoTo U1: ElseIf Cells(i, "B").Value = "C" Then GoTo C1: ElseIf Cells(i, "B").Value = "A" Then GoTo A1: ElseIf Cells(i, "B").Value = "G" Then GoTo G1: End If 'UX Block U1: If Cells(i + 1, "B").Value = "U" Then GoTo UU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo UC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo UA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo UG2: End If 'UUX Block UU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Phe" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Leu" End If GoTo EndOfAcids: 'UCX Block UC2: Cells(a, "C").Value = "Ser" GoTo EndOfAcids: 'UAX Block UA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Tyr" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Stop Codon" End If GoTo EndOfAcids: 'UGX Block UG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Cys" ElseIf Cells(i + 2, "B").Value = "A" Then Cells(a, "C").Value = "Stop Codon" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Trp" End If GoTo EndOfAcids: 'CX Block C1: If Cells(i + 1, "B").Value = "U" Then GoTo CU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo CC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo CA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo CG2: End If 'CUX Block CU2: Cells(a, "C").Value = "Leu" GoTo EndOfAcids: 'CCX Block CC2: Cells(a, "C").Value = "Pro" GoTo EndOfAcids: 'CAX Block CA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "His" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Gln" End If GoTo EndOfAcids: 'CGX Block CG2: Cells(a, "C").Value = "Arg" GoTo EndOfAcids: 'AX Block A1: If Cells(i + 1, "B").Value = "U" Then GoTo AU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo AC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo AA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo AG2: End If 'AUX Block AU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Or Cells(i + 2).Value = "A" Then Cells(a, "C").Value = "Ile" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Met" End If GoTo EndOfAcids: 'ACX Block AC2: Cells(a, "C").Value = "Thr" GoTo EndOfAcids: 'AAX Block AA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asn" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Lys" End If GoTo EndOfAcids: 'AGX Block AG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Ser" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Arg" End If GoTo EndOfAcids: 'GX Block G1: If Cells(i + 1, "B").Value = "U" Then GoTo GU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo GC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo GA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo GG2: End If 'GUX Block GU2: Cells(a, "C").Value = "Val" GoTo EndOfAcids: 'GCX Block GC2: Cells(a, "C").Value = "Ala" GoTo EndOfAcids: 'GAX Block GA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asp" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Glu" GoTo EndOfAcids: 'GGX Block GG2: Cells(a, "C").Value = "Gly" GoTo EndOfAcids: EndOfAcids: i = i + 3 a = a + 1 Loop End Sub 

尝试这个

 Option Explicit Sub RNATrascription() Dim i As Long Dim a As Long Dim dat As String i = 2 Do While Cells(i, "A").Value <> "" Select Case LCase(Cells(i, "A").Value) Case "a": dat = "U" Case "t": dat = "A" Case "g": dat = "C" Case "c": dat = "G" Case Else MsgBox "You have mis typed your DNA sequence" End End Select Cells(i, "B") = dat i = i + 1 Loop i = 2 a = 2 Dim cc2 As String Dim cc3 As String Do While Cells(i, "B").Value <> "" cc2 = Cells(i, "B") & Cells(i + 1, "B") cc3 = cc2 & Cells(i + 2, "B") dat = "" Select Case cc2 Case "uc": dat = "Ser" Case "cu": dat = "Leu" Case "cc": dat = "Pro" Case "ac": dat = "Thr" Case "gu": dat = "Val" Case "gc": dat = "Ala" End Select If dat = "" Then Select Case cc3 Case "uuu", "uuc": dat = "Phe" Case "uua", "uug": dat = "Ley" Case "uau", "uac": dat = "Tyr" Case "uaa", "uag", "uga": dat = "Stop Codon" Case "ugu", "ugc": dat = "Sys" Case "ugg": dat = "Trp" Case "cau": dat = "His" Case "caa": dat = "Gln" Case "cgc": dat = "Arg" Case "auu", "aua": dat = "Ile" Case "aug": dat = "Met" Case "aau", "agu", "agc": dat = "Asn" Case "aaa", "aga", "agg": dat = "Lys" Case "gau", "gac": dat = "Asp" Case "gaa", "gag": dat = "Glu" Case Else: dat = "ERROR" End Select End If Cells(a, "C").Value = dat i = i + 3 a = a + 1 Loop End Sub 

你的代码应该被格式化为这样的东西….如果你是这样做的,你可能已经注意到, end if在GAX块中没有end if

 Option Explicit Sub RNATrascription() Dim i As Long Dim a As Long i = 2 a = 2 Do While Cells(i, "A").Value <> "" If Cells(i, "A").Value = "A" Or Cells(i, "A").Value = "a" Then Cells(i, "B").Value = "U" ElseIf Cells(i, "A").Value = "T" Or Cells(i, "A").Value = "t" Then Cells(i, "B").Value = "A" ElseIf Cells(i, "A") = "G" Or Cells(i, "A").Value = "g" Then Cells(i, "B") = "C" ElseIf Cells(i, "A") = "C" Or Cells(i, "A").Value = "c" Then Cells(i, "B") = "G" ElseIf Cells(i, "A") <> "A" Or Cells(i, "A") <> "a" Or Cells(i, "A") <> "T" Or Cells(i, "A") <> "t" Or Cells(i, "A") <> "G" Or Cells(i, "A") <> "g" Or Cells(i, "A") <> "C" Or Cells(i, "A") <> "c" Then MsgBox "You have mis typed your DNA sequence" End If i = i + 1 Loop Do While Cells(i, "B").Value <> "" 'X Block If Cells(i, "B").Value = "U" Then GoTo U1: ElseIf Cells(i, "B").Value = "C" Then GoTo C1: ElseIf Cells(i, "B").Value = "A" Then GoTo A1: ElseIf Cells(i, "B").Value = "G" Then GoTo G1: End If 'UX Block U1: If Cells(i + 1, "B").Value = "U" Then GoTo UU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo UC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo UA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo UG2: End If 'UUX Block UU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Phe" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Leu" End If GoTo EndOfAcids: 'UCX Block UC2: Cells(a, "C").Value = "Ser" GoTo EndOfAcids: 'UAX Block UA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Tyr" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Stop Codon" End If GoTo EndOfAcids: 'UGX Block UG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Cys" ElseIf Cells(i + 2, "B").Value = "A" Then Cells(a, "C").Value = "Stop Codon" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Trp" End If GoTo EndOfAcids: 'CX Block C1: If Cells(i + 1, "B").Value = "U" Then GoTo CU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo CC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo CA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo CG2: End If 'CUX Block CU2: Cells(a, "C").Value = "Leu" GoTo EndOfAcids: 'CCX Block CC2: Cells(a, "C").Value = "Pro" GoTo EndOfAcids: 'CAX Block CA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "His" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Gln" End If GoTo EndOfAcids: 'CGX Block CG2: Cells(a, "C").Value = "Arg" GoTo EndOfAcids: 'AX Block A1: If Cells(i + 1, "B").Value = "U" Then GoTo AU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo AC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo AA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo AG2: End If 'AUX Block AU2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Or Cells(i + 2).Value = "A" Then Cells(a, "C").Value = "Ile" ElseIf Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Met" End If GoTo EndOfAcids: 'ACX Block AC2: Cells(a, "C").Value = "Thr" GoTo EndOfAcids: 'AAX Block AA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asn" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Lys" End If GoTo EndOfAcids: 'AGX Block AG2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Ser" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Arg" End If GoTo EndOfAcids: 'GX Block G1: If Cells(i + 1, "B").Value = "U" Then GoTo GU2: ElseIf Cells(i + 1, "B").Value = "C" Then GoTo GC2: ElseIf Cells(i + 1, "B").Value = "A" Then GoTo GA2: ElseIf Cells(i + 1, "B").Value = "G" Then GoTo GG2: End If 'GUX Block GU2: Cells(a, "C").Value = "Val" GoTo EndOfAcids: 'GCX Block GC2: Cells(a, "C").Value = "Ala" GoTo EndOfAcids: 'GAX Block GA2: If Cells(i + 2, "B").Value = "U" Or Cells(i + 2, "B").Value = "C" Then Cells(a, "C").Value = "Asp" ElseIf Cells(i + 2, "B").Value = "A" Or Cells(i + 2, "B").Value = "G" Then Cells(a, "C").Value = "Glu" GoTo EndOfAcids: 'GGX Block GG2: Cells(a, "C").Value = "Gly" GoTo EndOfAcids: EndOfAcids: i = i + 3 a = a + 1 Loop End Sub