Sub ATGCCount()
Dim DataSht As Worksheet
Set DataSht = ActiveSheet
Dim cntA As Double
Dim cntT As Double
Dim cntG As Double
Dim cntC As Double
Dim CountSheet As Worksheet
Worksheets.Add Before:=Sheets(1)
Set CountSheet = Sheets(1)
CountSheet.[A1:E1] = Array("SEQUENCE NUMBER", "A", "T", "G", "C")
DataSht.Activate
Dim SequenceCount As Long
For i = 1 To ActiveSheet.UsedRange.Rows.Count
If Application.WorksheetFunction.CountA(Rows(i)) > 0 Then
For j = 1 To Columns.Count
Select Case Cells(i, j)
Case "A": cntA = cntA + 1
Case "T": cntT = cntT + 1
Case "G": cntG = cntG + 1
Case "C": cntC = cntC + 1
End Select
Next j
Else
SequenceCount = SequenceCount + 1
CountSheet.Cells(SequenceCount + 1, 1) = SequenceCount
CountSheet.Cells(SequenceCount + 1, 2) = cntA
CountSheet.Cells(SequenceCount + 1, 3) = cntT
CountSheet.Cells(SequenceCount + 1, 4) = cntG
CountSheet.Cells(SequenceCount + 1, 5) = cntC
cntA = 0
cntT = 0
cntG = 0
cntC = 0
End If
Next i
End Sub
This makes a new page at the beginning of the workbook with a summary of the sequences and their counts. It is giving some extra sequences on the sample data because of the deleted info (showing 7 extra sequences with no data) but it should work nicely on your actual data. Paste into a regular module and run from the sheet with the data on it.
Bookmarks