首页 > 解决方案 > VBA - 在不同的列中添加不同的公式

问题描述

我有一张桌子,并成功创建了一个 vba 代码,它添加了一个 Vlookup 公式并向下拖动列。

Dim lastRow As Long
lastRow = Cells(Rows.Count, 8).End(xlUp).Row
Range("H5:H" & lastRow).Formula = "=VLOOKUP(A5,'XXX!$AA$5:$AM$2000,8,0)"
Range("H5:H" & lastRow).Value = Range("H5:H" & lastRow).Value

我现在遇到的问题是我想用所有不同的公式对大约 5 个其他列做同样的事情......我试图复制上面的代码,但更改了列和公式,但不断收到错误或不正确的结果。

IE

Dim lastRow As Long
lastRow = Cells(Rows.Count, 8).End(xlUp).Row
Range("H5:H" & lastRow).Formula = "=VLOOKUP(A5,'XXX!$AA$5:$AM$2000,8,0)"
Range("H5:H" & lastRow).Value = Range("H5:H" & lastRow).Value


lastRow = Cells(Rows.Count, 9).End(xlUp).Row
Range("G5:G" & lastRow).Formula = "=VLOOKUP(A5,'XXX!$AA$5:$AM$2000,9,0)"
Range("G5:G" & lastRow).Value = Range("G5:G" & lastRow).Value

任何帮助都感激不尽

谢谢

标签: vbaexcel

解决方案


推荐阅读