excel - apply vlookup formula for variable no.of rows -


i have excel sheet in first 3 columns pivot table , whenever refresh it, no. of rows may change. columns e,f,g,h,i use vlookup formula based on columns a,b,c.

since no. of rows changing, how can make sure vlookup formula automatically adjusts columns e,f,g,h,i based on no. of rows of a,b,c ?

attached image in can see formula didn't apply last 3 rows , have manually drag cells if work. enter image description here

somewhat brute force like

' refreshed pivot table ' ' assumes variable ws refers worksheet ' assumes formulas start on row 2  ws.range("e2:i2").copy ws.range("e3:e" & ws.usedrange.rows.count) 

then put if statement around formula in column e (and similar if statements on other columns):

=if(c2="","",vlookup(...)) 

you can more robust way determine how many rows on left versus right. or step through like:

for = 1 ws.usedrange.rows.count     if(ws.cells(i,3).value = "")         ws.range("e" & & ":i" & i).clearcontents     else         '''  apply formulas / values in columns e through of row     end if next 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -