2017-10-17 165 views
1
With newexcel.Sheets("Analysis") 
    .Range("I1").AutoFilter Field:=9, Criteria1:="<>#N/A" 
    .Range("E1").AutoFilter Field:=5, Criteria1:="InActive" 
    .Range("D1").AutoFilter Field:=4, Criteria1:=(BLANK) 
    .AutoFilter.Range.SpecialCells(xlCellTypeVisible).Copy newexcel.Sheets("Test").Range("A1") 
    firstRow139 = .AutoFilter.Range.Offset(1).SpecialCells(xlCellTypeVisible).Row 
End With 

With newexcel.Sheets("Analysis").Range(newexcel.Sheets("Analysis").Cells(firstRow139, 4), newexcel.Sheets("Analysis").Cells(lastRow139, 4)) 
    .Formula = "=VLOOKUP(A&firstRow139,'Test'!A:D,4,0)" 
End With 

在这里,VLOOKUP,它没有采取firstRow139值VBA动态范围问题

回答

1

你需要采取的变量firstRow139公式的"部分之外。

当前的公式更改,如:

.Formula = "=VLOOKUP(A&firstRow139,'Test'!A:D,4,0)" 

到:

.Formula = "=VLOOKUP(A" & firstRow139 & ",'Test'!A:D,4,0)" 

我可能会改变你如何使用With到药结构:

With newexcel.Sheets("Analysis") 
    .Range(.Cells(firstRow139, 4), .Cells(lastRow139, 4)).Formula = "=VLOOKUP(A" & firstRow139 & ",'Test'!A:D,4,0)" 
End With