Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. Dim dBT As Object 'global dictionary
  2.  
  3. Sub buttonpresscount()
  4.  
  5. 'constants for column positions
  6. Const COL_BLOCK As Long = 1
  7. Const COL_TRIAL As Long = 2
  8. Const COL_ACT As Long = 7
  9. Const COL_AOI As Long = 8
  10.  
  11. Dim rng As Range, lastrow As Long, sht As Worksheet
  12. Dim d, r As Long, k, resBT()
  13.  
  14. Set sht = Worksheets("full test")
  15. lastrow = Cells(Rows.Count, 3).End(xlUp).Row
  16. Set dBT = CreateObject("scripting.dictionary")
  17.  
  18. Set rng = sht.Range("B7:I" & lastrow)
  19.  
  20. d = rng.Value 'get the data into an array
  21.  
  22. ReDim resBT(1 To UBound(d), 1 To 1) 'resize the array which will
  23. ' be placed in ColT
  24.  
  25. 'get unique combinations of Block and Trial and pressedcounts for each
  26. For r = 1 To UBound(d, 1)
  27. k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key
  28. dBT(k) = dBT(k) + IIf(d(r, COL_ACT) <> "", 1, 0)
  29. Next r
  30.  
  31. 'populate array with appropriate counts for each row
  32. For r = 1 To UBound(d, 1)
  33. k = d(r, 1) & "|" & d(r, 2) 'create key
  34. resBT(r, 1) = dBT(k) 'get the count
  35. Next r
  36.  
  37. 'place array to sheet
  38. sht.Range("T7").Resize(UBound(resBT, 1), 1) = resBT
  39.  
  40. 'clear dictionary
  41. dBT.RemoveAll
  42.  
  43. 'count AOI entries
  44. For r = 1 To UBound(d, 1)
  45. k = d(r, COL_BLOCK) & "|" & d(r, COL_TRIAL) 'create key
  46. dBT(k) = dBT(k) + IIf(d(r, COL_AOI) = "AOI Entry", 1, 0)
  47. Next r
  48.  
  49. 'populate array with appropriate counts for each row
  50. For r = 1 To UBound(d, 1)
  51. k = d(r, 1) & "|" & d(r, 2) 'create key
  52. resBT(r, 1) = dBT(k) 'get the count
  53. Next r
  54.  
  55. 'place array to sheet
  56. sht.Range("U7").Resize(UBound(resBT, 1), 1) = resBT
  57.  
  58.  
  59. End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement