简体   繁体   English

计算空白行数

[英]Count number of blank rows

I have a database of peptide sequences.我有一个肽序列数据库。 I would like to add the different numbers of blank rows under the protein's name so I could analyze the data in the next step.我想在蛋白质名称下添加不同数量的空白行,以便在下一步分析数据。

The blank rows are in column D, eg 73 blank rows for Solyc09g007080.3.1, as shown in this screenshot.空白行位于 D 列,例如 Solyc09g007080.3.1 有 73 个空白行,如此屏幕截图所示。
这个截图

I found code to add specific numbers of blank rows under each row and I adjusted that code to be used with my list.我找到了在每行下添加特定数量的空白行的代码,并调整了该代码以与我的列表一起使用。 It only runs for two protein names every time I run the code when I chose about 34,000 numbers in column D for the blank rows to be added.当我在 D 列中选择大约 34,000 个数字作为要添加的空白行时,每次运行代码时,它只运行两个蛋白质名称。

Sub InsertSpecificNumberOfBlankRows()
    Dim xRg As Range
    Dim I, xNum, xLastRow, xFstRow, xCol, xCount As Long

    Set xRg = Selection
    If xRg Is Nothing Then Resume Next
    Application.ScreenUpdating = False
    xLastRow = xRg(1).End(xlDown).Row
    xFstRow = xRg.Row
    xCol = xRg.Column
    xCount = xRg.Count

    For I = xLastRow To xFstRow Step -1
        xNum = Cells(I, xCol)
        If IsNumeric(xNum) And xNum > 0 Then
            Rows(I + 1).Resize(xNum).Insert
            xCount = xCount + xNum
        End If
    Next
    Application.ScreenUpdating = True

End Sub

Insert Empty Rows插入空行

Option Explicit

Sub InsertSpecificNumberOfBlankRows()

    If Not TypeOf Selection Is Range Then Exit Sub ' 'Selection' is not a range
    
    Dim srg As Range: Set srg = Selection.Columns(1)
    Dim ws As Worksheet: Set ws = srg.Worksheet
    
    Dim sLastRow As Long: sLastRow = srg.Cells(srg.Rows.Count).Row
    Dim sFirstRow As Long: sFirstRow = srg.Row
    Dim sCol As Long: sCol = srg.Column
    
    Application.ScreenUpdating = False

    Dim sValue As Variant
    Dim irCount As Long
    Dim r As Long
    
    For r = sLastRow To sFirstRow Step -1
         sValue = ws.Cells(r, sCol).Value
         If IsNumeric(sValue) Then
             If sValue >= 1 Then
                 ws.Rows(r + 1).Resize(sValue).Insert _
                      xlShiftDown, xlFormatFromLeftOrAbove
                 irCount = irCount + sValue
             End If
         End If
    Next r
     
    Application.ScreenUpdating = True

    MsgBox "Inserted " & irCount & " rows.", vbInformation

End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM