我在Excel的工作簿中有两张纸; “Sheet1”和“Sheet2”。 Sheet1有很多数据将更改,而shee2有两个活动单元格。这些单元格等于另一页面的前两个单元格中的任何单元格。也就是说,如果sheet1上的(A1& A2)等于(3& 5)然后在sheet2上它们将等于相同的东西。是的,对于Excel VBA部分。我制作一个创建“sheet2”的宏。因此,宏需要从“sheet1:将它们放在范围”A3&中取出范围“A1:A2”。在sheet2上的A4“。因此,当sheet1 A1上的值发生变化时,则在sheet2 A3上它也会发生变化。
我只是想知道如何在另一张纸上复制单元格的动态值。这是可能的,因为我发誓我能找到的最接近的东西是vlookup
,这似乎很复杂,因为这样一个简单的任务,我甚至不确定它会起作用。
TL; DR如何从VBA中没有vlookup
的其他工作表中复制单元格的动态值?
答案 0 :(得分:0)
You can go to your Excel sheet -> Formula Ribbon -> Name Manager -> New Name
Set your new names to be equal to $A$1 and $A$2. When you insert rows etc. in Excel, the Name Manager will automatically shift around so it stays pointing at the 'old cells'.
Then in VBA, you can refer to these as Range("NAME_FOR_A1")
or Range("NAME_FOR_A2")
, and it will always refresh to the 'updated' target.
Or, reading your question again, you could simply take the values from A1 & A2, put those values to a variable, and pass them to A3 & A4. So, something like:
A1Variable = Sheets(1).Range("A1").Formula
A2Variable = Sheets(1).Range("A2").Formula
Sheets(2).Range("A3") = A1Variable
Sheets(2).Range("A4") = A2Variable
Vlookup
is not relevant here; that's an Excel Formula tool, not VBA. Hypothetically you could use it, but only rarely would that be simpler than using a VBA approach.