VBA / Excel如何将ActiveCell保存为对象

我需要从Excel中的列表构buildlogin文本。 我用macros尝试自己,写一个小脚本。 基本上我有2个单元一个旁边。 第一个获得ssh密钥名,第二个获得密码。 这2个值取决于机器的os,在其他字段中指定。 最后,我有一个与os名称的表和密码旁边的ssh密钥。

这是我写的:

Function FindKey(FirstCell As Range) As String ' ' FindKey Macro ' Find the ssh key in function of the OS ' Dim Find As Boolean Dim Cell As Range Dim OS As String Cell = ActiveCell.Address ActiveCell.Offset(0, 4).Value = OS Find = False While Not Find ActiveCell = FirstCell.Address If ActiveCell.Value = OS Then FindKey = ActiveCell.Offset(0, 1).Value Cell.Offset(0, 1).Value = ActiveCell.Offset(0, 2).Value Cell.Select Find = True Else ActiveCell.Offset(1, 0).Select If IsEmpty(ActiveCell) Then Cell.Select FindKey = CVErr(xlErrNull) Find = True End If End If Wend ' End Function 

我真的不知道我是如何写这个的。 我只能在一个variables中存储单元格地址吗? 我可以用它作为下一个对象吗?

谢谢你的时间,祝你有美好的一天

 dim yourCell as Range set yourCell = ActiveCell 

 set yourCell = FirstCell 

设置对象引用时,需要使用关键字集