Vba计数(能否达到如下效果)如图
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/17 06:05:41
Vba计数(能否达到如下效果)如图
B列任意位置输入任意数,可同时向上、向下计数(90数内)如:输入4,可同时向上、向下计数4、14、24、34、44、54、64、74、84、94;又如输入7,可同时向上、向下计数7、17、27、37、47、57、67、77、87、97.如图:
试试
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If IsNumeric(Target.Value) = False Then Exit Sub
Dim iNum&, iRow&, iCount%
iNum = Target.Value
If iNum > 10 Then Exit Sub
iRow = Target.Row
iCount = 1
Application.EnableEvents = False
Cells(iRow + iNum - 1, 2) = iNum
Cells(iRow - iNum + 1, 2) = iNum
Do
If iRow - iNum - iCount * 10 > 0 Then Cells(iRow - iNum + 1 - iCount * 10, 2) = iNum + iCount * 10
If iRow + iNum + iCount * 10 < Rows.Count Then Cells(iRow + iNum - 1 + iCount * 10, 2) = iNum + iCount * 10
iCount = iCount + 1
Loop Until iCount > 9
Application.EnableEvents = True
End Sub
再问: 谢谢老师,达到效果,如想调整在w列,如何改动代码。
再答: Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 23 Then Exit Sub
If IsNumeric(Target.Value) = False Then Exit Sub
Dim iNum&, iRow&, iCount%
iNum = Target.Value
If iNum > 10 Then Exit Sub
iRow = Target.Row
iCount = 1
Application.EnableEvents = False
Cells(iRow + iNum - 1, 23) = iNum
Cells(iRow - iNum + 1, 23) = iNum
Do
If iRow - iNum+1 - iCount * 10 > 0 Then Cells(iRow - iNum + 1 - iCount * 10, 23) = iNum + iCount * 10
If iRow + iNum-1 + iCount * 10 < Rows.Count Then Cells(iRow + iNum - 1 + iCount * 10, 23) = iNum + iCount * 10
iCount = iCount + 1
Loop Until iCount > 9
Application.EnableEvents = True
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 2 Then Exit Sub
If IsNumeric(Target.Value) = False Then Exit Sub
Dim iNum&, iRow&, iCount%
iNum = Target.Value
If iNum > 10 Then Exit Sub
iRow = Target.Row
iCount = 1
Application.EnableEvents = False
Cells(iRow + iNum - 1, 2) = iNum
Cells(iRow - iNum + 1, 2) = iNum
Do
If iRow - iNum - iCount * 10 > 0 Then Cells(iRow - iNum + 1 - iCount * 10, 2) = iNum + iCount * 10
If iRow + iNum + iCount * 10 < Rows.Count Then Cells(iRow + iNum - 1 + iCount * 10, 2) = iNum + iCount * 10
iCount = iCount + 1
Loop Until iCount > 9
Application.EnableEvents = True
End Sub
再问: 谢谢老师,达到效果,如想调整在w列,如何改动代码。
再答: Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column <> 23 Then Exit Sub
If IsNumeric(Target.Value) = False Then Exit Sub
Dim iNum&, iRow&, iCount%
iNum = Target.Value
If iNum > 10 Then Exit Sub
iRow = Target.Row
iCount = 1
Application.EnableEvents = False
Cells(iRow + iNum - 1, 23) = iNum
Cells(iRow - iNum + 1, 23) = iNum
Do
If iRow - iNum+1 - iCount * 10 > 0 Then Cells(iRow - iNum + 1 - iCount * 10, 23) = iNum + iCount * 10
If iRow + iNum-1 + iCount * 10 < Rows.Count Then Cells(iRow + iNum - 1 + iCount * 10, 23) = iNum + iCount * 10
iCount = iCount + 1
Loop Until iCount > 9
Application.EnableEvents = True
End Sub
如下VBA 语句,能否再简?Sheets("sheet2").Range("a6:c6,e6:g6,i6:k6")可以赋
[如图]CAD在VBA中画圆和点,为什么报错啊?
铝合金压铸件能否阳极氧化,达到良好的表面效果?
怎样达到除锈和防锈效果 亚硝酸钠和盐酸能混合用吗?能否达到除锈和防锈作用?
如图;如下:
exl 每10000计数为1单位,大于等于5000小于10000为0.5单位 小于5000的计为0.效果应如下表:A B
如何用两个普通两个接线柱的开关控制一盏灯,达到双联开关的效果.
氮化耐腐蚀:低碳钢如Q235钢 渗氮,要想达到长时间的耐腐蚀效果,
室内拍摄家具(如沙发)时怎么的灯光设备和布置才能达到像太阳光的效果?
能否用血球计数板计数细菌的细胞数?
能否用血球计数板计数细菌细胞数
如何用vba在excel中自定义一个函数