我在VBA中有一个功能
Function VLOOKUPnew(ValueToLook As Range, Interval As Range, ColIndex As Integer) As Variant
它接受$ A $ 1:$ D $ 500但不接受Name_of_worksheet!$ A $ 1:$ D $ 500
我该如何解决?
编辑:这与此问题copy/pastspecial cell format in VBA inside function, don't work
有关答案 0 :(得分:0)
问题是函数内部的代码。你需要改变这个:
fMatch = Application.Match(ValueToLook, Range(Interval.Address()).Columns(1), 0)
' Obtem o endereço da célula que contem o valor do VLOOKUP
' **********************************************
CellOrigin = Interval.Cells(fMatch, Interval.Columns.Count).Address()
进入这个:
fMatch = Application.Match(ValueToLook, Interval.Worksheet.Range(Interval.Address()).Columns(1), 0)
' Obtem o endereço da célula que contem o valor do VLOOKUP
' **********************************************
CellOrigin = "'" & Interval.Worksheet.Name & "'" & Interval.Cells(fMatch, Interval.Columns.Count).Address()
否则它将搜索错误的工作表,并从错误的单元格中复制格式。