Macro AA_ParseConverts a text string in a single cell or in several consecutive cells in the same column into individual characters in consecutive cells to the right of the source string. The original string will be deleted, the cells containing the parsed string formatted. Usage:
Sub AA_Parse() 'converts a text string in a single cell into individual characters in consecutive cells 'you can select a range of cells within the same column 'do not select more than one column, cells to the right of this column will be overwritten If Selection.Columns.Count = 0 Then 'Error, nothing selected MsgBox Prompt:="No cells selected, please select the sequences you wish to parse" Exit Sub End If If Selection.Columns.Count > 1 Then 'Error, more than one column selected MsgBox Prompt:="More than one column selected, select only one column" Exit Sub End If 'get extent of current selection i1 = Selection.Row i2 = i1 + Selection.Rows.Count - 1 j = Selection.Column n = 0 'length of longest sequence For i = i1 To i2 Step 1 'for all selected cells aaa = Cells(i, j) If TypeName(aaa) = "String" Then a = Len(aaa) If a > 254 - j Then 'Not enough cells available for entire sequence a = 250 - j Msg = "The sequence is too long, only the first " & a & " amino acids used" MsgBox Prompt:=Msg End If If a > n Then n = a 'determine length of longest sequence For k = 1 To a Step 1 'parse the sequence Cells(i, j + k) = Mid(aaa, k, 1) Next k Else 'Error, is not a character string End If Next i Selection.Delete Shift:=xlToLeft 'Delete original strings Range(Cells(i1, j), Cells(i2, j + n)).Select 'select sequence alignment Selection.ColumnWidth = 1 'set column width to 1 End Sub |
|
|||||||||||||||||
Last Modified by A.Honegger |