我要做的第一件事是创建一个脚本字典,将一列中每一行的键设置为零。在随后的代码中,当条件满足时,我将Key的项拉为整数,将其添加1,然后在字典中将0替换为1。
为了测试代码,当我专门调用密钥时,我得到了预期的1。当我将该词典的项目转置为一列时,它给了我全零。当我将其设置为遍历For循环时,将Items放入列中的后续行中,我仍然得到全零。
我不担心最高限额,我正在检查的只有40名招聘人员。
编辑:我睡着了,以为我会放一些更多的测试代码。创建字典后,我立即对字典进行了计数,结果达到了41。在执行完代码后,我又放置了一个计数,发现它达到了42。
什么允许您在字典中拥有两个相同的键?
想法?
LRR和LR?是供参考的最后一行变量
'This creates the dictionary. Recruiter Key with a 0 item Set RecGoalCount = CreateObject("scripting.dictionary") For Each RecDesk In Sheets("Recruiters").Range("B2:B" & LRR) RecGoalCount.Add RecDesk, 0 Next RecDesk
''''Here is the code that will change the dictionary item to a 1. The way _ ''''it processes the sheet right now, there is only one instance where all _ ''''are true which is why only 1 item gets changed from a 0 to a 1. RecMatch = 0 For Each job In Sheets("Sheet2").Range("A2:A" & LRS2) For Each job2 In Sheets("Sheet1").Range("D2:X" & LRS1) OneOfInQW = WorksheetFunction.CountIf(Sheets("Sheet1").Range("D2:X" & LRS1), job) CurrentCol = job2.Column TrgtCol = CurrentCol - 4 TrgtCell = job2.Offset(0, -TrgtCol).Value2 RefCell = job.Offset(0, 1).Value2 If job = job2 And OneOfInQW = 1 And RefCell >= TrgtCell Then LRS3 = Sheets("Sheet3").Cells(Rows.Count, 1).End(xlUp).Row TrgtRec = CurrentCol - 1 TrgtCol = CurrentCol - 2 TrgtCell = job2.Offset(0, -TrgtCol).Value2 TrgtKey = job2.Offset(0, -TrgtRec).Value2 Sheets("Sheet3").Range("A" & (LRS3 + 1)).Value = TrgtCell RecMatch = Int(RecGoalCount(TrgtKey)) RecMatch = RecMatch + 1 RecGoalCount.Item(TrgtKey) = Str(RecMatch) job2.EntireRow.ClearContents Sheets("Sheet3").Range("B" & (LRS3 + 1)).Value = job Sheets("Sheet3").Range("C" & (LRS3 + 1)).Value = job.Offset(0, 1) job.Clear job.Interior.ColorIndex = 4 Sheets("Sheet3").Range("A" & (LRS3 + 1)).Interior.ColorIndex = 4 Exit For End If Next job2 Next job
Sheets("Recruiters").Range("E2:E" & LRR) = Application.Transpose(RecGoalCount.Items) 'This is where I get all 0s despite a condition in the code changing exactly 1 Item to a 1 Sheets("Recruiters").Range("F2:F" & LRR) = Application.Transpose(RecGoalCount.Keys) 'This is just proving to me that it captured the correct keys with the correct names, check. Sheets("Recruiters").Range("H2") = RecGoalCount("14CBBPG") 'This proves to me that the Item became a 1 Recs = RecGoalCount.Count 'This proves to me that after the code that changes the item, the total _ count of the dictionary didn't change either.
'This code iterates through the dictionary keys to give the items, and it _ gives me all 0s despite one of the items being turned into a 1 x = 2 For Each Rec In RecGoalCount Sheets("Recruiters").Range("E" & x) = RecGoalCount(Rec) x = x + 1 Next Rec
我要做的第一件事是创建一个脚本字典,将一列中每一行的键设置为零。在随后的代码中,当条件满足时,我将键的项拉为...
一旦我能够确定自己是在添加新密钥而不是更新密钥,我只需要在Google上搜索字典中可能具有重复外观的密钥。这是我创建字典的方式。我将键添加为单元格而不是值。