范围查找replaceVBA VBScript excel编译器错误missin指令

我试图find并replaceVBA脚本(在Excel中)工作,但我得到的错误,它需要说明。 即时通讯相当新的脚本/ VBA所以不介意的问题eaze 🙂

Worksheets("General").Columns("C").Replace _ What:="Y", Replacement:="N", _ SearchOrder:=xlByColumns, MatchCase:=True 

“什么”后popup错误

它声明了它的一个编译器错误

我的来源: https : //msdn.microsoft.com/en-us/library/office/ff194086.aspx

错误

删除“常规”和纸张的input号码。 我的猜测是你有一个错字。 同时擦除“C”,并留下我写这个列的数量

 Sub test Worksheets(1).Columns(3).Replace What:="Y", Replacement:="N", searchOrder:=xlByColumns, MatchCase:=True End Sub 

如果你得到错误。 这可能是因为列中没有包含“Y”的string

尝试:

 Worksheets("General").Columns("C").Replace What:="Y", Replacement:="N", SearchOrder:=xlByColumns, MatchCase:=True 

这可能是你的_没有正确放置。

pipe理得到它的工作。 我用了:

 Dim myxl Dim mywb Dim mysh Set myxl = CreateObject("Excel.Application") myxl.Visible = True myxl.DisplayAlerts = False myxl.EnableEvents = False '20160412 BM open the workbook Set mywb = myxl.Workbooks.Open(mysrcfile, True, False, , , , , , , True) '20160523 BM open the sheet Set mysh = mywb.WorkSheets("General") 'The parameters in the following order for: what, replacement,lookat, searchorder, matchcase mywb.Sheets("General").Columns("C").Replace "Y", "N", 1, 2, True mywb.Save mywb.Close false Set mywb = Nothing myxl.EnableEvents = True myxl.DisplayAlerts = True myxl.Quit Set myxl = Nothing