字典项目=每个分组的列中最后一行的单元格值

这是我的代码:

Dim dBT As Object 'global dictionary Sub buttonpresscount() 'constants for column positions Const COL_BLOCK As Long = 1 Const COL_TRIAL As Long = 2 Const COL_ACT As Long = 7 Const COL_AOI As Long = 8 Const COL_RT As Long = 16 Dim rng As Range, lastrow As Long, sht As Worksheet Dim d, r As Long, k, resBT() Set sht = Worksheets("full test") lastrow = Cells(Rows.Count, 3).End(xlUp).Row Set dBT = CreateObject("scripting.dictionary") Set rng = sht.Range("B7:Q" & lastrow) d = rng.Value 'get the data into an array ReDim resBT(1 To UBound(d), 1 To 1) 'resize the array which will ' be placed in ColT 'get unique combinations of Block and Trial and pressedcounts for each For r = 1 To UBound(d, 1) k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key dBT(k) = dBT(k) + IIf(d(r, COL_ACT) <> "", 1, 0) Next r 'populate array with appropriate counts for each row For r = 1 To UBound(d, 1) k = d(r, 1) & "|" & d(r, 2) 'create key resBT(r, 1) = dBT(k) 'get the count Next r 'place array to sheet sht.Range("T7").Resize(UBound(resBT, 1), 1) = resBT 'clear dictionary dBT.RemoveAll 'count AOI entries For r = 1 To UBound(d, 1) k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key dBT(k) = dBT(k) + IIf(d(r, COL_AOI) = "AOI Entry", 1, 0) Next r 'populate array with appropriate counts for each row For r = 1 To UBound(d, 1) k = d(r, 1) & "|" & d(r, 2) 'create key resBT(r, 1) = dBT(k) 'get the count Next r 'place array to sheet sht.Range("U7").Resize(UBound(resBT, 1), 1) = resBT Call createsummarytable Call PopSummaryAOI(dBT) dBT.RemoveAll For r = 1 To UBound(d, 1) k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key dBT(k) = Cells(r, COL_RT).Value Next r 'Populate array with last row reaction time for each trial For r = 1 To UBound(d, 1) k = d(r, 1) & "|" & d(r, 2) 'create key resBT(r, 1) = dBT(k) 'get the count Next r Call PopSummaryRT(dBT) End Sub 

我想要这样一行: dBT(k) = Cells(r, COL_RT).Value 。每个试验的值Q列的最后一个单元格的值。 目前我没有得到任何错误,但是我想要打印的值没有被打印,所以我不能正确地定义单元的地址。

以下是我的数据的屏幕截图:

这是我期望看到的值打印:

这是将值打印到表的代码:

 Sub PopSummaryRT(dict) Dim sht As Worksheet, k, b, t, f, f2 Set sht = ThisWorkbook.Sheets("datasummary") For Each k In dict b = Split(k, "|")(0) 'get block t = Split(k, "|")(1) 'get trial 'find the block Set f = sht.Columns(1).Find(what:=b, lookat:=xlWhole, LookIn:=xlValues) If Not f Is Nothing Then 'find the trial under that block Set f2 = f.Offset(1, 0).EntireRow.Find(what:=t, lookat:=xlWhole, LookIn:=xlValues) If Not f2 Is Nothing Then f2.Offset(2, 0).Value = dict(k) End If Next k End Sub 

更改

 For r = 1 To UBound(d, 1) k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key dBT(k) = Cells(r, COL_RT).Value '<--| wrong line Next r 

 For r = 1 To UBound(d, 1) k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key dBT(k) = d(r, COL_RT) '<--| corrected line Next r 

因为Cells引用所有活动的单元格,从单元格“A1” 开始 ,而从单元格“B7”收集相关的值