在vba中添加动态单元格引用 [英] adding a dynamic cell reference in vba

查看:230
本文介绍了在vba中添加动态单元格引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码使用vba将公式插入到单元格中。
代码插入一个超链接,一些静态文本导致一个文件路径,然后在我的文件路径的末尾,我想要添加动态单元格引用,例如A,然后是行数。

I am using the following code to insert a formula into a cell using vba. The code inserts a hyperlink with some static text leading to a file path and then at the end of my file path I want to be able to add a dynamic cell reference, for instance A and then the number of the row.

在我的列中的单元格中有文件夹的名称。我正在使用DestRow定义当前的行号。所以我的问题是我如何更正我的公式,以便当链接被点击它打开链接以获得正确的文件夹名称的行被点击?谢谢

In my cell in column A I have the names of folders. I am using DestRow to define the current row number. So my question is how can I correct my formula so that when the link is clicked it opens the link to get the correct folder name of the row clicked? Thanks

 ws2.Range("S" & DestRow).Formula = "=HYPERLINK(""\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\"" & K" & DestRow & ",""Attached"")"


推荐答案

尝试

ws2.Range("S" & DestRow).Formula = "=HYPERLINK(""\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\" & ws2.Range("K" & DestRow).Value & """,""Attached"")"

FWIW,我讨厌使用引用的字符串。

FWIW, I hate working with quoted strings as well.

附录:应该在动态文件夹之后添加静态文件名:

Addendum: This should do for adding a static filename after the dynamic folder:

ws2.Range("S" & DestRow).Formula = "=HYPERLINK(""\\UKSH000-FILE06\Purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\" & ws2.Range("K" & DestRow).Value & "\audit.xls"",""Attached"")"

这篇关于在vba中添加动态单元格引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆