Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Newsgroup Archive
Excel Newsgroups
Excel Worksheets
Want to write function/macro for DNA reverse-complement
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
Reply to thread
Message
[QUOTE="JE McGimpsey, post: 3510683"] One way: Public Function Complement(sInput As String) As Variant Dim i As Long For i = 1 To Len(sInput) Select Case Mid(sInput, i, 1) Case "A" Complement = Complement & "C" Case "C" Complement = Complement & "A" Case "G" Complement = Complement & "T" Case "T" Complement = Complement & "G" Case Else Complement = CVErr(xlErrValue) Exit For End Select Next i End Function Another (no error checking): Public Function Complement(sInput As String) As Variant With Application sInput = .Substitute(sInput, "A", "%") sInput = .Substitute(sInput, "C", "A") sInput = .Substitute(sInput, "%", "C") sInput = .Substitute(sInput, "T", "%") sInput = .Substitute(sInput, "G", "T") sInput = .Substitute(sInput, "%", "G") End With Complement = sInput End Function Note: Application.Substitute can be replaced by VBA's Replace(), but it won't work in XL97 or MacXL. [/QUOTE]
Verification
Post reply
Forums
Archive
Newsgroup Archive
Excel Newsgroups
Excel Worksheets
Want to write function/macro for DNA reverse-complement
Top