2017-10-17 171 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