Loop for VBA code?
I see what you mean now. Try this revision
BTW, the ProtWeight macro aggregates a variable Y, if the character is Y,
but does not use it anywhere.
Sub IEP()
'
' IEP Macro
' Macro created 07/01/98 by Gerry Shaw
'
iLastRow = Cells(Rows.Count, "a").End(xlUp).Row
For i = 1 To iLastRow
C = 0: D = 0: E = 0: H = 0: K = 0: R = 0: Y = 0
For j = 1 To Len(Cells(i, "A").Value)
Select Case Mid$(Cells(i, "A").Value, j, 1)
Case "C": C = C + 1
Case "D": D = D + 1
Case "E": E = E + 1
Case "H": H = H + 1
Case "K": K = K + 1
Case "R": R = R + 1
Case "Y": Y = Y + 1
End Select
Next j
' Define array of nine elements containing the pKa
' values of amino acids , N And C - termini
Dim pK(8) As Double
pK(0) = 0.000446 ' C-term
pK(1) = 0.0000851 ' Glu
pK(2) = 0.000126 ' Asp
pK(3) = 0.000000000661 ' Lys
pK(4) = 0.00000000102 ' Arg
pK(5) = 0.00000000447 ' Cys
pK(6) = 0.000000912 ' His
pK(7) = 0.000000000776 ' Tyr
pK(8) = 0.000000000166 ' N-term
For pH = 2 To 12 Step 0.1
' calculates HH, the proton concentration
HH = Exp(-pH * Log(10))
' positive charge is function of proton conc,
' number of K, R and H and N -terminus
pcharge = HH * K / (HH + pK(3)) + HH * R / _
(HH + pK(4)) + HH * H / (HH + pK(6)) + _
HH / (HH + pK(8))
' negative charge is function of proton conc,
' number of Tyr, Cys, Glu,Asp and C-terminus
ncharge = Y * (1 - (HH / (HH + pK(7)))) + _
C * (1 - (HH / (HH + pK(5)))) + 1 - _
(HH / (HH + pK(1))) + E * (1 - (HH / (HH + pK(1)))) +
_
D * (1 - (HH / (HH + pK(2))))
' exits for loop when pcharge is less than ncharge
If (pcharge <= ncharge) Then Exit For
Next pH
Cells(i, "B").Value = "pKa = " & Format(pH, "fixed")
Next i
End Sub
Sub Nucweight()
'
' Nucweight Macro
' Macro recorded 07/02/98 by Gerry Shaw
' This version for DNA sequences: for RNA MW for A = 329.2,
' U = 306.1, G = 345.2, C= 305.2
'
iLastRow = Cells(Rows.Count, "a").End(xlUp).Row
For i = 1 To iLastRow
MW = 0: Z = 0
For j = 1 To Len(Cells(i, "A").Value)
Select Case Mid$(Cells(i, "A").Value, j, 1)
Case "A": MW = MW + 313.2
Case "T": MW = MW + 304.2
Case "G": MW = MW + 329.2
Case "C": MW = MW + 289.2
Case Else: Z = Z + 1
End Select
Next j
MW = MW + 18
If MW 18 Then
Cells(i, "B").Value = "Selection includes " & Len(Cells(i,
"A").Value) - Z & _
" bases, " & _
"Molecular Weight= " & MW & " Daltons"
ElseIf MW = 18 Then
Cells(i, "B").Value = "No sequence selected"
End If
Next i
End Sub
Sub Protweight()
'
' Protweight Macro
' Macro recorded 07/02/98 by Gerry Shaw
'
iLastRow = Cells(Rows.Count, "a").End(xlUp).Row
For i = 1 To iLastRow
MW = 0: Y = 0: Z = 0
For j = 1 To Len(Cells(i, "A").Value)
Select Case Mid$(Cells(i, "A").Value, j, 1)
Case "A": MW = MW + 71.09
Case "C": MW = MW + 103.15
Case "D": MW = MW + 115.1
Case "E": MW = MW + 129.13
Case "F": MW = MW + 147.19
Case "G": MW = MW + 57.07
Case "H": MW = MW + 137.16
Case "I": MW = MW + 113.17
Case "K": MW = MW + 128.19
Case "L": MW = MW + 113.17
Case "M": MW = MW + 131.31
Case "N": MW = MW + 114.12
Case "P": MW = MW + 97.13
Case "Q": MW = MW + 128.15
Case "R": MW = MW + 156.2
Case "S": MW = MW + 87.09
Case "T": MW = MW + 101.12
Case "V": MW = MW + 99.15
Case "W": MW = MW + 186.23
Case "Y": MW = MW + 163.19
Y = Y + 1
Case Else: Z = Z + 1
End Select
Next j
MW = MW + 18
If MW 18 Then
Cells(i, "B").Value = "Selection includes " & Len(Cells(i,
"A").Value) - Z & _
" amino acids, Molecular Weight= " & _
Format(MW, "fixed") & " Daltons"
Else
Cells(i, "B").Value = "No Sequence Selected"
End If
Next i
End Sub
--
HTH
Bob Phillips
(remove nothere from email address if mailing direct)
"paulinoluciano" wrote in message
ups.com...
Thank you Bob Phillips. The molecular weight VBA codes worked exactly
how I want however the IEP code have some strange problem! If you test
the same sequence in different cells you will obtain distinct values. I
can not understand what is happening...
Luciano
|