Need help with formatting this worksheet, might require VBA

mfitz51

New Member
Joined
Jun 6, 2024
Messages
7
Office Version
  1. 365
Platform
  1. Windows
  2. Web
Hi, I am trying to group individual samples into pools of samples. I need to be able to say how many samples will be going into the pool, and what the pool will be called. After the pools are assigned, I need them to move to my export format for downstream use. In the downstream, all the samples of a pool must be listed in one cell.

Below, the raw import file of all the sample data. Could be 90-2000+ samples
Library Pooling Template.xls
ABCDE
1EntitySourceInput SampleUDI lotPrep date
2GI762_LibDNA-020GI762UDI_1 0023/19/25
3GI763_LibDNA-021GI763UDI_2 0023/19/25
4GI764_LibDNA-022GI764UDI_3 0023/19/25
5GI765_LibDNA-023GI765UDI_P4 0013/19/25
6GI766_LibDNA-024GI766UDI_P5 0013/19/25
Raw Import


Next, all the samples (Libraries) will be assigned to a pool.
Needs
1. User input of number of libraries (samples) per pool (B3)
2. The pool has an alphanumeric ID that will be assigned (B6-B15) and needs to populate in column D according to the number of samples per pool (B3)
3. Column F will populate & concatenate with =CONCAT('Raw Import'!A2,", ") It needs to have the comma at the end for the down stream application
4. Column G is directly from 'Raw Import'!D, doesn't need manipulation
Cell Formulas
RangeFormula
B2B2=COUNTA('Raw Import'!A2:A2000)
F2:F21F2=CONCAT('Raw Import'!A2,", ")
G2:G21G2='Raw Import'!D2
B4B4=B2/B3
D2:D11D2=$B$6
D12:D21D12=B$7


Next, all the pools need to be converted to the export format for the next downstream step.
Needs
1. Pool alpha numeric ID needs to populate in column c
2. The libraries/samples must populate in ONE cell per pool ID in column D. This is critical for down stream usage
Columns A & B left empty intentionally
Library Pooling Template.xls
ABCDE
1EntityProject CodePool ID LibrariesPooling Date
21234GI762_Lib, GI763_Lib, GI764_Lib, GI765_Lib, GI766_Lib, GI767_Lib, GI768_Lib, GI769_Lib, GI770_Lib, GI771_Lib3/21/25
3ABCDGI772_Lib GI773_Lib GI774_Lib GI775_Lib GI776_Lib GI777_Lib GI778_Lib GI779_Lib GI780_Lib GI781_Lib3/21/25
45678GI782_Lib GI783_Lib GI784_Lib GI785_Lib GI786_Lib GI787_Lib GI788_Lib GI789_Lib GI790_Lib GI791_Lib3/21/25
Export Format
Cell Formulas
RangeFormula
C2C2='Pool Assignment '!D2
C3C3='Pool Assignment '!D12
C4C4='Pool Assignment '!D22
E2:E4E2=TODAY()
 
Please test whether this code is working correctly, or provide additional raw data for correction, Thank You
VBA Code:
Sub x()
    Dim a As Worksheet, b As Worksheet, c As Worksheet
    Dim d As Long, e As Long, f As Long
    Dim g As Long, h As Long
    Dim i As Integer, j As Integer
    Dim k As String, l As String
    
    Set a = ThisWorkbook.Sheets("Raw Import")
    Set b = ThisWorkbook.Sheets("Pool Assignment")
    Set c = ThisWorkbook.Sheets("Export Format")
    
    d = a.Cells(a.Rows.Count, 1).End(xlUp).Row
    e = b.Cells(b.Rows.Count, 2).End(xlUp).Row
    j = b.Range("B3").Value
    
    c.Cells(1, 1).Value = "Entity"
    c.Cells(1, 2).Value = "Project Code"
    c.Cells(1, 3).Value = "Pool ID"
    c.Cells(1, 4).Value = "Libraries"
    c.Cells(1, 5).Value = "Pooling Date"
    
    g = 6
    h = 2
    Dim m As Long: m = 2
    Dim n As Long: n = 2
    
    Do While g <= e And h <= d
        k = b.Cells(g, 2).Value
        l = ""
        
        For i = 1 To j
            If h > d Then Exit For
            
            b.Cells(m, 4).Value = k
            b.Cells(m, 5).Value = i
            b.Cells(m, 6).Value = a.Cells(h, 1).Value
            b.Cells(m, 7).Value = a.Cells(h, 4).Value
            
            If l = "" Then
                l = a.Cells(h, 1).Value
            Else
                l = l & vbNewLine & a.Cells(h, 1).Value
            End If
            
            h = h + 1
            m = m + 1
        Next i
        
        c.Cells(n, 3).Value = k
        c.Cells(n, 4).Value = l
        c.Cells(n, 4).WrapText = True
        c.Cells(n, 5).Formula = "=TODAY()"
        
        g = g + 1
        n = n + 1
    Loop
    
    
End Sub
 
Upvote 0
Solution

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top