How to get VLOOKUP to select down to the lowest row in VBA?

后端 未结 2 1607
逝去的感伤
逝去的感伤 2021-01-27 14:12

Looking to automate the insertion of a VLOOKUP formula in a cell. When recording the macro I instruct it to populate the columns below with the same formula. Works great, howev

2条回答
  •  甜味超标
    2021-01-27 14:46

    @nbayly said it, plenty of posts on this. Infact i have provided an answer to this before here:

    How to Replace RC Formula Value with Variable

    below is slightly modified for a dynamic range, which is what i believe you are looking for

    For j = n To 10 Step -1
        If Cells(j, 1).Value = "" Then
            Cells(j, 1).Formula = "=VLookup(RC20,Previous!R2C2:R273C22,17,FALSE)"
        End If
    Next j
    

    remember to define j as long and n=sheets("sheetname)".cells(rows.count,1).end(xlup).row

    replace 10 in j = n to 10 with the starting row number

提交回复
热议问题