在前面一篇文章
名称标引
中,我们建立了一个字典,并且根据字典中的规则对食品企业的各个发明名称进行了标引。这篇文章,我们将依据上文中的标引词对奖励系数进行加合,对标引词个数、标引词对应的奖励系数进行统计。
我们对标引词进行统计的思路是:
① 预计将标引词统计在右方的第8列中,将每个标引词的个数统计在第9列中,将每个标引词对应的发明创造的奖励系数统计在第10列中。给第8、9、10列赋予表头,并设置一个初始值为1的bottom变量,用于标识当前已写入的行。
写为:
Sheet6.Cells(1, 8) = "类别"
Sheet6.Cells(1, 9) = "统计量"
Sheet6.Cells(1, 10) = "奖励系数加合"
bottom = 1
② 在第一层和第二层循环中,从Sheet6的第5列第2行开始,按照先行后列的方式依次遍历所有发明名称的标引词。将标引词赋值给字符串变量name1。写为:
For i = 2 To 24
For j = 5 To 7
name1 = Sheet6.Cells(i, j)
*判断语句*
Next
Next
③ 判断如果标引词所在的单元格不为空,则将标引词、个数1以及奖励系数写入第8、9、10列。
写为:
If Len(name1) <> 0 Then
Sheet6.Cells(bottom + 1, 8) = name1
Sheet6.Cells(bottom + 1, 9) = 1
Sheet6.Cells(bottom + 1, 10) = Sheet6.Cells(i, 4)
bottom = bottom + 1
*循环语句*
End If
④ 在第三层循环中,判断新写入的标引词与之前的标引词是否存在重复。如果重复,则将已有标引词的个数加一,并且将新写入标引词的奖励系数加到已有标引词的奖励系数上,同时将新写入的行的8、9、10列置为空,同时将用于标识当前已写入的行的bottom变量减1。
写为:
For m = 1 To bottom - 1
name2 = Sheet6.Cells(m, 8)
If StrComp(name1, name2) = 0 Then
Sheet6.Cells(m, 9) = Sheet6.Cells(m, 9) + 1
Sheet6.Cells(m, 10) = Sheet6.Cells(m, 10) + Sheet6.Cells(i, 4)
Sheet6.Cells(bottom, 8) = ""
Sheet6.Cells(bottom, 9) = ""
Sheet6.Cells(bottom, 10) = ""
bottom = bottom - 1
Exit For
End If
Next