请修改如下代码VBA?
如下:代码是计算21个顺序与数值相同的个数代码,我想改为26个的顺序与数值相同的个数代码要如何修改?Sub相同21个顺序与数值的个数计算()SetDic=CreateOb...
如下:代码是计算21个顺序与数值相同的个数代码,我想改为26个的顺序与数值相同的个数代码要如何修改?
Sub 相同21个顺序与数值的个数计算()
Set Dic = CreateObject("scripting.dictionary")
x = Selection(Selection.Count).Row
y = Selection(1).Row
Z = Selection(1).column
For i = x To y + 20 Step -1
Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z)) = Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z)) + 1
Next i
For j = x To y + 20 Step -1
Cells(j, Z - 1) = Dic(Cells(j, Z) & "|" & Cells(j - 1, Z) & "|" & Cells(j - 2, Z) & "|" & Cells(j - 3, Z) & "|" & Cells(j - 4, Z) & "|" & Cells(j - 5, Z) & "|" & Cells(j - 6, Z) & "|" & Cells(j - 7, Z) & "|" & Cells(j - 8, Z) & "|" & Cells(j - 9, Z) & "|" & Cells(j - 10, Z) & "|" & Cells(j - 11, Z) & "|" & Cells(j - 12, Z) & "|" & Cells(j - 13, Z) & "|" & Cells(j - 14, Z) & "|" & Cells(j - 15, Z) & "|" & Cells(j - 16, Z) & "|" & Cells(j - 17, Z) & "|" & Cells(j - 18, Z) & "|" & Cells(j - 19, Z) & "|" & Cells(j - 20, Z))
Next j
End Sub 展开
Sub 相同21个顺序与数值的个数计算()
Set Dic = CreateObject("scripting.dictionary")
x = Selection(Selection.Count).Row
y = Selection(1).Row
Z = Selection(1).column
For i = x To y + 20 Step -1
Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z)) = Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z)) + 1
Next i
For j = x To y + 20 Step -1
Cells(j, Z - 1) = Dic(Cells(j, Z) & "|" & Cells(j - 1, Z) & "|" & Cells(j - 2, Z) & "|" & Cells(j - 3, Z) & "|" & Cells(j - 4, Z) & "|" & Cells(j - 5, Z) & "|" & Cells(j - 6, Z) & "|" & Cells(j - 7, Z) & "|" & Cells(j - 8, Z) & "|" & Cells(j - 9, Z) & "|" & Cells(j - 10, Z) & "|" & Cells(j - 11, Z) & "|" & Cells(j - 12, Z) & "|" & Cells(j - 13, Z) & "|" & Cells(j - 14, Z) & "|" & Cells(j - 15, Z) & "|" & Cells(j - 16, Z) & "|" & Cells(j - 17, Z) & "|" & Cells(j - 18, Z) & "|" & Cells(j - 19, Z) & "|" & Cells(j - 20, Z))
Next j
End Sub 展开
1个回答
展开全部
改一下代码,即可
Sub 相同26个顺序与数值的个数计算()
Set Dic = CreateObject("scripting.dictionary")
x = Selection(Selection.Count).Row
y = Selection(1).Row
Z = Selection(1).column
For i = x To y + 25 Step -1
Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z)) = Dic(Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & Cells(i - 20, Z) & "|" & Cells(i - 21, Z) & "|" & Cells(i - 22, Z) & "|" & Cells(i - 23, Z) & "|" & Cells(i - 24, Z) & "|" & Cells(i - 25, Z)) + 1
Next i
For j = x To y + 25 Step -1
Cells(j, Z - 1) = Dic(Cells(j, Z) & "|" & Cells(j - 1, Z) & "|" & Cells(j - 2, Z) & "|" & Cells(j - 3, Z) & "|" & Cells(j - 4, Z) & "|" & Cells(j - 5, Z) & "|" & Cells(j - 6, Z) & "|" & Cells(j - 7, Z) & "|" & Cells(j - 8, Z) & "|" & Cells(j - 9, Z) & "|" & Cells(j - 10, Z) & "|" & Cells(j - 11, Z) & "|" & Cells(j - 12, Z) & "|" & Cells(j - 13, Z) & "|" & Cells(j - 14, Z) & "|" & Cells(j - 15, Z) & "|" & Cells(j - 16, Z) & "|" & Cells(j - 17, Z) & "|" & Cells(j - 18, Z) & "|" & Cells(j - 19, Z) & "|" & Cells(j - 20, Z) & "|" & Cells(j - 21, Z) & "|" & Cells(j - 22, Z) & "|" & Cells(j - 23, Z) & "|" & Cells(j - 24, Z) & "|" & Cells(j - 25, Z))
Next j
End Sub
更多追问追答
追答
这是因为一行里面代码太长,再修改一下
Sub 相同26个顺序与数值的个数计算()
Dim t
Set Dic = CreateObject("scripting.dictionary")
x = Selection(Selection.Count).Row
y = Selection(1).Row
Z = Selection(1).Column
For i = x To y + 25 Step -1
t = Cells(i, Z) & "|" & Cells(i - 1, Z) & "|" & Cells(i - 2, Z) & "|" & Cells(i - 3, Z) & "|" & Cells(i - 4, Z) & "|" & _
Cells(i - 5, Z) & "|" & Cells(i - 6, Z) & "|" & Cells(i - 7, Z) & "|" & Cells(i - 8, Z) & "|" & Cells(i - 9, Z) & "|" & _
Cells(i - 10, Z) & "|" & Cells(i - 11, Z) & "|" & Cells(i - 12, Z) & "|" & Cells(i - 13, Z) & "|" & Cells(i - 14, Z) & "|" & _
Cells(i - 15, Z) & "|" & Cells(i - 16, Z) & "|" & Cells(i - 17, Z) & "|" & Cells(i - 18, Z) & "|" & Cells(i - 19, Z) & "|" & _
Cells(i - 20, Z) & "|" & Cells(i - 21, Z) & "|" & Cells(i - 22, Z) & "|" & Cells(i - 23, Z) & "|" & Cells(i - 24, Z) & "|" & Cells(i - 25, Z)
Dic(t) = Dic(t) + 1
Cells(i, Z - 1) =Dic(t)
Next i
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询