wps中用vba将一个工作表中的数据一键保存到别一个工作表中,代码出现下标越界错误,求教
这是网上找来的代码,自己有一定的vc基础能看懂,但没接触过vba,稍改了下运行时出现这个错误,请大神指导Subjizhang()DimWS1AsWorksheet,WS2...
这是网上找来的代码,自己有一定的vc基础能看懂,但没接触过vba,稍改了下运行时出现这个错误,请大神指导
Sub jizhang()
Dim WS1 As Worksheet, WS2 As Worksheet
Dim Rnum1, Rnum2
Set WS1 = Worksheets("尚品美居销售单")
Set WS2 = Worksheets("记账")
Rnum2 = WS2.Range("b65536").End(xlUp).Row + 1
Rnum1 = 6
Do Until WS1.Cells(Rnum1, 1) = "" Or WS1.Cells(Rnum1, 1) = "本单小计"
WS2.Cells(Rnum2, 2) = WS1.[b2]
WS2.Cells(Rnum2, 3) = WS1.[b3]
WS1.Cells(Rnum1, 1).Resize(1, 5).Copy WS2.Cells(Rnum2, 5)
Rnum1 = Rnum1 + 1
Rnum2 = Rnum2 + 1
Loop
End Sub 展开
Sub jizhang()
Dim WS1 As Worksheet, WS2 As Worksheet
Dim Rnum1, Rnum2
Set WS1 = Worksheets("尚品美居销售单")
Set WS2 = Worksheets("记账")
Rnum2 = WS2.Range("b65536").End(xlUp).Row + 1
Rnum1 = 6
Do Until WS1.Cells(Rnum1, 1) = "" Or WS1.Cells(Rnum1, 1) = "本单小计"
WS2.Cells(Rnum2, 2) = WS1.[b2]
WS2.Cells(Rnum2, 3) = WS1.[b3]
WS1.Cells(Rnum1, 1).Resize(1, 5).Copy WS2.Cells(Rnum2, 5)
Rnum1 = Rnum1 + 1
Rnum2 = Rnum2 + 1
Loop
End Sub 展开
展开全部
代码本身没有语法错误
在微软的EXCEL下正常运行
不知道这个出错是否与WPS有关。。。。
代码有点小错误
以下按“记账”的表格结构改了一下
改过的地方都注释了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | Sub jizhang() Dim WS1 As Worksheet, WS2 As Worksheet Dim Rnum1, Rnum2 Set WS1 = Worksheets( "尚品美居销售单" ) Set WS2 = Worksheets( "记账" ) Rnum2 = WS2.Range( "b65536" ). End (xlUp).Row + 1 Rnum1 = 5 '起始行 Do Until WS1.Cells(Rnum1, 1) = "" Or WS1.Cells(Rnum1, 1) = "本单小计" WS2.Cells(Rnum2, 1) = WS1.[b2] 'A列 WS2.Cells(Rnum2, 2) = WS1.[b3] 'B列 WS1.Cells(Rnum1, 1).Resize(1, 6).Copy WS2.Cells(Rnum2, 3) '扩展6列 '复制到C列 Rnum1 = Rnum1 + 1 Rnum2 = Rnum2 + 1 Loop End Sub |
追问
谢谢,我调试找到原因了,是记帐这两个字的原因,网上复制代码的时候没改记账工作表,自己工作表打成了记帐,晕死,我把工作表的记帐两字复制到代码里就好了,好多年没碰代码了,都还给大学了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询