我这个程序在一个EXCEL中运行没问题,但是当我把代码复制到另一个EXCEL中是就提示如下:

Public Sub format1()
Dim ar, br(1 To 60000, 1 To 9), i, j, arr, t, k, n
'maxrow1 = Cells(Rows.Count, "B").End(xlUp).Row
Columns("E:E").Select
' Range("E2").Activate
Selection.Replace What:="~*", Replacement:="×", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Columns("E:E").Select
' Range("E2").Activate
Selection.Replace What:="X", Replacement:="×", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
ar = Range("a3", [f65536].End(3))

For i = 1 To UBound(ar)
arr = Split(ar(i, 5), "×")
'If UBound(arr) - LBound(arr) + 1 > 2 Then ReDim Preserve arr(LBound(arr) To UBound(arr) - 1)
ReDim Preserve arr(LBound(arr) To UBound(arr) - 1)
t = Evaluate(Join(arr, "*"))
n = n + t
'For j = n To n - Val(ar(i, 5)) + 1 Step -1
For j = n To n - t + 1 Step -1
k = k + 1
If j = n - t + 1 Then
br(j, 1) = ar(i, 1)
br(j, 2) = ar(i, 2)
br(j, 3) = ar(i, 3)
br(j, 4) = ar(i, 4)
br(j, 5) = ar(i, 5)
br(j, 9) = ar(i, 6)
End If
br(j, 6) = t - k + 1
Next j
k = 0
Next
With Sheets(1)
.Rows("3:" & .Rows.Count).Clear
With .[a3].Resize(n, 9)
.Value = br
.Font.Size = 9
.Resize(, 10).Borders.LineStyle = xlContinuous
End With
End With
End Sub

若点击调试的话会提出 t = Evaluate(Join(arr, "*"))这个语句有问题,请大神指导




吃鸡游戏
浏览 195回答 2
2回答

慕妹3146593

应该是Join(arr, "*")的结果出错。

动漫人物

是不是你的arr中的数据中含有非计算符号?实际上你不一定用split和join函数换来换去,直接用替换,把 "×"替换成“*"用函表函数直接得到t值t = Evaluate(replace(ar(i,5),"×", "*"))你是根据E列算出插入的行数,是吗?
打开App,查看更多内容
随时随地看视频慕课网APP