VBA从列中删除括号
问题描述:
我试图通过搜索三列并删除括号来格式化电子表格。目前,我有:VBA从列中删除括号
Range("B:D").Select
Selection.Replace What:="(", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Selection.Replace What:=")", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
当我运行代码,我得到:
运行时错误“1004”: 应用程序定义或对象定义的错误”
答
它的工作原理如果你用表名出线,不使用选择
Sheet1.Range("B:D").Replace What:="(", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
Sheet1.Range("B:D").Replace What:=")", Replacement:="", LookAt:=xlPart, _
SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
ReplaceFormat:=False
必须有另外一个问题,因为这运行正常,我 –
'范围?(“B:d”)'可以参考'Sheet1'在'Workbook1'或'Sheet2'在'Workbook2'中,等等。哪一个是正确的? 我想说的是你必须在上下文中使用代码! –
Maciej,这应该在所有情况下运行,因为B-D列将存在于每张纸上。 –