excel vba循环出错,程序卡死
最近学习vba,想写一段代码在a列填充年(2000~2013),b列填充月(1~12),但代码一执行excel整个就死了,请大神帮忙看看咋回事。谢谢啦!!!Subyear...
最近学习vba,想写一段代码在a列填充年(2000~2013),b列填充月(1~12),但代码一执行excel整个就死了,请大神帮忙看看咋回事。谢谢啦!!!
Sub year_month()
Dim i, j As Integer
Cells(1, 1).Resize(, 2) = Array("year", "month")
Cells(2, 1).Resize(12) = Array(2000)
For i = 1 To 12
Cells(1 + i, 2) = i
Next
j = 0
Do
Cells(14 + j, 1) = Cells(2 + j, 1) + 1
Cells(14 + j, 2) = Cells(2 + j, 2)
Loop while Cells(14 + j, 1) <2014
End Sub
这是执行后的结果 展开
Sub year_month()
Dim i, j As Integer
Cells(1, 1).Resize(, 2) = Array("year", "month")
Cells(2, 1).Resize(12) = Array(2000)
For i = 1 To 12
Cells(1 + i, 2) = i
Next
j = 0
Do
Cells(14 + j, 1) = Cells(2 + j, 1) + 1
Cells(14 + j, 2) = Cells(2 + j, 2)
Loop while Cells(14 + j, 1) <2014
End Sub
这是执行后的结果 展开
1个回答
推荐于2016-06-03
展开全部
我不知道你怎样想的,下面是我写:
Sub Macro1()
Dim i, j, l As Integer
Cells(1, 1).Resize(, 2) = Array("year", "month")
l = 2
For i = 2000 To 2013
For j = 1 To 12
Cells(l, 1) = i
Cells(l, 2) = j
l = l + 1
Next
Next
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询