VBA程序出现sub或者function未定义
Subtest()DimI,j,KAsLongDima,bAsStringDimuseSheetAsExcel.WorksheetSetuseSheet=ThisWork...
Sub test()
Dim I, j, K As Long
Dim a, b As String
Dim useSheet As Excel.Worksheet
Set useSheet = ThisWorkbook.Worksheets("Sheet1")
a = useSheet.Cells(1, 1).Value
b = Trim(Right(Substitute(a, "_", Rept(" ", Len(a))), Len(a)))
End Sub
会提示sub或者function未定义
但是如果我把b=Trim(Right(Substitute(a, "_", Rept(" ", Len(a))), Len(a)))删除就可以正常运行
为什么? 展开
Dim I, j, K As Long
Dim a, b As String
Dim useSheet As Excel.Worksheet
Set useSheet = ThisWorkbook.Worksheets("Sheet1")
a = useSheet.Cells(1, 1).Value
b = Trim(Right(Substitute(a, "_", Rept(" ", Len(a))), Len(a)))
End Sub
会提示sub或者function未定义
但是如果我把b=Trim(Right(Substitute(a, "_", Rept(" ", Len(a))), Len(a)))删除就可以正常运行
为什么? 展开
3个回答
展开全部
SUBSTITUTE和rept是工作表函数,需要用WORKSHEETFUNCTION来调用。
Sub test()
Dim I, j, K As Long
Dim a, b As String
Dim useSheet As Excel.Worksheet
Set useSheet = ThisWorkbook.Worksheets("Sheet1")
a = useSheet.Cells(1, 1).Value
b = Trim(Right(Application.WorksheetFunction.Substitute(a, "_", Application.WorksheetFunction.Rept(" ", Len(a))), Len(a)))
End Sub
展开全部
Substitute错了,应该修改为replace
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Substitute 换成 Application.Substitute 看看可以不
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询