我需要填写Col H(如图中的红色文本)如下:

在另一个Sub()中,我找到了如何使用"C01D01.00“作为重置线索来重置每个新主题的值。这可以用于填充范围内不依赖于单元格的数据(例如“LLOQ下面的基线吗?”)但我无法搞清楚如何“设置”一个范围,读取范围,识别Col I中是否有" no“单元格,然后在Col H中返回"no”(如果在Col I中没有"no“,则返回”是“,然后移动到下一个”范围“)。想法?
请看下面我是如何编程的。
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发布于 2022-11-01 00:55:23
像这样的事情应该有效:
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 Subhttps://stackoverflow.com/questions/74269887
复制相似问题