我需要填寫 Col H(例如,請參見影像中的紅色文本),如下所示:
- 列出了 3 個科目(以灰色背景分隔)(編號為 Col C)
- 每個主題都有多個資料點(每行一個 - Col D 用于資料點“名稱”)
- (未顯示)每個受試者的多個資料點在多個測驗上運行,并按測驗、受試者、時間點排序。(參見 Col E 的測驗),這意味著每個“統一 ID”/“主題 ID”被多次使用。該資料應單獨考慮(例如,不應將受試者 8 脂聯素結果與受試者 8 Areg 資料進行比較)
- 測驗未檢測到某些資料,并在 Col J ("<LLOQ") 和 Col I ("Yes" for <LLOQ aka not detected) 中都進行了標記。
- 我需要幫助設計一個程式來回答“來自該主題(和測驗)的所有樣本是否低于 LLOQ?”。因此程式需要檢測每個受試者的資料必須在一個塊中查看 填寫 Col H “所有樣本低于 LLOQ?” 在繼續下一個主題之前。如果范圍內沒有 <LLOQ 樣本,則 Col H 中的每個單元格將為“否”。如果有一些樣本 <LLOQ 和一些樣本不是 <LLOQ,則范圍內 Col H 中的每個單元格將是“否”(見灰色主題)。但是,如果某個物件的所有樣本均 <LLOQ,則對于范圍內的所有單元格,H 中的值必須為“是”。

在另一個 Sub() 中,我想出了如何使用“C01D01.00”作為重置提示來重置每個新主題的值。這可以填充不依賴于范圍內單元格的資料(例如 G 列中的“基線是否低于 LLOQ?”。但我無法弄清楚如何“設定”范圍,通讀范圍,識別如果任何單元格在 Col I 中為“否”,然后在 Col H 中回傳“no”(如果在范圍內的 Col I 中沒有“no”,則在 Col H 中回傳“yes”,然后移動到下一個“范圍” ”)。想法?
請參閱下文了解我是如何撰寫 Col G 的。
Sub BaselineBelowLLOQ()
Sheets("Cyt-Data").Activate
Dim NewSubject As String
Dim SubjectBL As String
Dim BaselineRow As Integer
For i = 2 To 1000000
If Sheets("Cyt-Data").Cells(i, 2).Value = "" Then
Exit For
End If
NewSubject = Cells(i, 3).Value
If Not SubjectBL = NewSubject And Cells(i, 4).Value = "C01D01.00" Then
SubjectBL = NewSubject
BaselineRow = i
ElseIf Not SubjectBL = NewSubject And Not Cells(i, 4).Value = "C01D01.00" Then
SubjectBL = ""
End If
If Not SubjectBL = "" Then
If Cells(BaselineRow, 9).Value = "Yes" Then
Cells(i, 7).Value = "Yes"
Else
Cells(i, 7).Value = "No"
End If
End If
Next i
End Sub
uj5u.com熱心網友回復:
像這樣的東西應該作業:
Sub BaselineBelowLLOQ()
Dim ws As Worksheet, i As Long, dict As Object, k As String
Dim subjId, testName, num1 As Long, num2 As Long
Set dict = CreateObject("scripting.dictionary")
Set ws = ThisWorkbook.Worksheets("Cyt-Data") 'or ActiveWorkbook...
For i = 2 To ws.Cells(Rows.Count, "B").End(xlUp).Row
subjId = ws.Cells(i, "C").Value
testName = ws.Cells(i, "E").Value
k = subjId & "<>" & testName 'SubjectId<>TestName combination
If Not dict.exists(k) Then 'new combination?
'count all rows for this combo
num1 = Application.CountIfs(ws.Columns("C"), subjId, _
ws.Columns("E"), testName)
'count rows for this combo with "Yes" in Col I
num2 = Application.CountIfs(ws.Columns("C"), subjId, _
ws.Columns("E"), testName, _
ws.Columns("I"), "Yes")
dict.Add k, IIf(num1 = num2, "Yes", "No") 'compare counts for this combo
'and store the Yes/No outcome
End If
'tag the row using the value we already figured out
ws.Cells(i, "H").Value = dict(k)
Next i
End Sub
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/526372.html
