Excel:查找并replace第一行和Excel表单

我想要一个代码来查找并replaceExcel表格第一行中的所有单元格。 我有以下代码通过search谷歌。

Sub FindReplace() Dim sht As Worksheet Dim fndList As Variant Dim rplcList As Variant Dim x As Long fndList = Array("Fname", "Lname", "Phone") rplcList = Array("First Name", "Last Name", "Mobile") For x = LBound(fndList) To UBound(fndList) For Each sht In ActiveWorkbook.Worksheets Rows(1).Replace What:=fndList(x), Replacement:=rplcList(x), _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False Next sht Next x End Sub 

这工作正常。 但是我们应该在代码本身中提及查找和replace列表。 如何使它从用户端获取input,而不是在代码中手动input。 input为文本或文件将是很好的。

 fndList = Split(Application.InputBox("List the values to be searched for in the following format: " & vbCrLf & "val1, val2, val3, ...", Type:=2), ",") '<--| this returns an array of 'String's rplcList = Split(Application.InputBox("List the values to be replaced in the following format: " & vbCrLf & "val1, val2, val3, ...", Type:=2), ",") '<--| this returns an array of 'String's For Each sht In ActiveWorkbook.Worksheets For x = LBound(fndList) To UBound(fndList) sht.Rows(1).Replace What:=fndList(x), Replacement:=rplcList(x), _ LookAt:=xlPart, SearchOrder:=xlByRows, MatchCase:=False, _ SearchFormat:=False, ReplaceFormat:=False Next x Next sht