简体   繁体   中英

vlookup with worksheet function vba without fixing the range

I want to write a vba code to do vlookup with worksheet function where my range is changing every time.I have written the below code:

dim ws as worksheet
set ws = thisworkbook.sheets("master sheet")
with ws
.range("V2:V91004").formula = "=vlookup(C2,sheet2!$A:$B,2,0)"
end with

I want to remove the Range ie 2:V91004 and let my code take the range itself because my lookupvalue (column C)row number varies from 75000 to 100000. Pls suggest..

I have found a way and its working fine. .range("V2:V91004").formula can be replaced by .range("V2:V" & range("C" & rows.count).end(xlup).row).formula ..

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM