尝试使用这种替代代码:
If k > 0 Then
Sht1.Cells(erow, 3) = CInt(sht3.Cells(i, 5).value) + 1
Debug.Print CInt(sht3.Cells(i, 5).value)
Sht1.Cells(erow, 4) = CInt(sht3.Cells(i, 6).value) + 1
Debug.Print CInt(sht3.Cells(i, 6).value)
Sht1.Cells(erow, 1) = Sht1.Cells(erow - 1, 1).value + 1
Debug.Print Sht1.Cells(erow - 1, 1).value
End If
,看看它打破。看看直接窗口。价值可能不是一个数字。
如果您编辑代码一点,你可能会得到你想要的东西:
Public Sub TestMe
If k > 0 Then
Sht1.Cells(erow, 3) = IncreaseWithOne(sht3.Cells(i, 5).value)
End If
End Sub
Public Function IncreaseWithOne(strValue As String) As String
Dim myVal As Long
myVal = Split(strValue, "-")(1)
IncreaseWithOne = Split(strValue, "-")(0) & "-" & Format(myVal + 1, "0000")
End Function
但它确实是好,如果你编辑你的问题,你想要什么。例如,你想分割字符串25-00001
,转换为整数并递增第二部分并返回25-00002
。因为将任何编程语言都不支持将整数添加到字符串。
什么是你的代码的问题? – Vityata
获取运行时错误13 –