我有一段代码需要更改,因此它可以在另一台计算机上工作,它是一个INDEX,MATCH公式,可以得到一些注释,无论如何,我的问题是,如果我更改路径,即使在我的计算机上方式(关闭的excel文件,通过我的代码访问以查找注释)我在ws.Range ... etc等行上出现了不匹配错误,如果有人知道问题出在哪里,那将使我难过。 / p>
Sub Thomas()
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
Dim lr As Long
Dim mnt As String, mnt2 As String
Dim xWb As Workbook
ThisWorkbook.UpdateLinks = xlUpdateLinksNever
Application.DisplayAlerts = False
mnt = InputBox("Filename")
mnt2 = "'H:\Documents\Thomas\[" & mnt & ".xls]Sheet1'" ' Change Sheet1 to the actual tabname
Set xWb = Workbooks.Open("\\data\home\ro\nbi\Documents\Thomas\" & mnt & ".xls")
ActiveWindow.Visible = False
lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
tx = Array("=INDEX(" & mnt2 & "!$G:$G,MATCH(1,(A2=" & mnt2 & "!$A:$A)*(C2=" & mnt2 & "!$C:$C),0))")
ws.Range("H2:H" & lr).FormulaArray = tx
ThisWorkbook.UpdateLinks = xlUpdateLinksAlways
Application.DisplayAlerts = True
xWb.Close savechanges:=False
End Sub
So the first one works and this one gives me a missmatch error
Sub Thomas3()
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
Dim lr As Long
Dim mnt As String, mnt2 As String
Dim xWb As Workbook
lr = ws.Cells(Rows.Count, "B").End(xlUp).Row
ThisWorkbook.UpdateLinks = xlUpdateLinksNever
Application.DisplayAlerts = False
mnt = InputBox("Filename")
mnt2 = "'Z:\Sales\city\Thomas\client\[" & mnt & ".xls]Sheet1'" ' Change Sheet1 to the actual tabname
Set xWb = Workbooks.Open("Z:\Sales\city\Thomas\client\" & mnt & ".xls")
ActiveWindow.Visible = False
tx = Array("=INDEX(" & mnt2 & "!$G:$G,MATCH(1,(A2=" & mnt2 & "!$A:$A)*(C2=" & mnt2 & "!$C:$C),0))")
ws.Range("H2:H" & lr).FormulaArray = tx
ThisWorkbook.UpdateLinks = xlUpdateLinksAlways
Application.DisplayAlerts = True
xWb.Close savechanges:=False
End Sub