excel 将位置(孔Id)特定数据添加到表中(基于96孔板)

vmdwslir  于 2023-03-04  发布在  其他
关注(0)|答案(1)|浏览(260)

我正试图与一个大型数据集,其中包含已从graphpad导出的csv文件.

我最终需要将这些表透视/合并成一个细长的格式,但首先需要为每个数字分配一个wellID。(忽略x轴,这些应该都覆盖在一个8x 12的网格上)我的想法是我可以在每个同名的列后面插入一个新的列,Intermediate,这里的希望是在融合之后,所有的Well_Id列将连接成一个沿着附加数据的列。问题还在于它也应该只与最新的列直接关联到它的右边。

我是编程新手,所以我想在投入太多时间之前,看看我的方法是否正确。下面是我开始编写的VBA脚本,但是在设置column + 1(需要对象)的占位符时,它抛出了一个错误。

Sub Assign_Plate_wells()
Dim iLastCol As Integer
Dim nxtcol As Integer

    
    'Counts to the last column and then works backwards
    iLastCol = Cells(1, Columns.Count).End(xlToLeft).Column

    For colx = iLastCol To 2 Step -1
        Columns(colx).Insert Shift:=xlToRight
           
            'Supposed to target the header of the newly created column and change the name
            Cells(1, colx).FormulaR1C1 = "Well_ID"
    
    Next

End Sub
jm2pwxwz

jm2pwxwz1#

这里有一个一步到位的方法:

Sub FormatOutput()
    Const NUM_PTS As Long = 8 'points per curve
    Dim wb As Workbook, wsSrc As Worksheet, wsDest As Worksheet
    Dim rngConcs As Range, rngData As Range, cDest As Range, col As Long
    Dim rwDest As Range, r As Long, wellRow As Long, wellCol As Long
    
    Set wb = ActiveWorkbook
    Set wsSrc = ActiveSheet
    Set wsDest = wb.Worksheets("listing") 'for example
    Set rwDest = wsDest.Rows(2)
    
    Set rngConcs = wsSrc.Range("A2").Resize(NUM_PTS)
    wellCol = 1
    Do While Application.CountA(rngConcs) > 0 'loop down the concentration column
        For col = 1 To 20                'loop across the readout columns
            Set rngData = rngConcs.Offset(0, col)
            If Application.CountA(rngData) > 0 Then 'any readout data here?
                For wellRow = 1 To NUM_PTS
                    rwDest.Cells(1).Value = rngConcs.Cells(wellRow).Value
                    rwDest.Cells(2).Value = WellLabel(wellRow, wellCol)
                    rwDest.Cells(3).Value = rngData.Cells(wellRow).Value
                    Set rwDest = rwDest.Offset(1)  'next row on output sheet
                Next wellRow
                wellCol = wellCol + 1 'next plate column
            End If
        Next col
    
        Set rngConcs = rngConcs.Offset(NUM_PTS + 1) 'next concs block (one blank line)
    Loop
End Sub

'return a well label given row and column number
Function WellLabel(rw As Long, col As Long) As String
    WellLabel = Chr(64 + rw) & Format(col, "00")
End Function

相关问题