以编程方式设置1个单元格始终具有与另一个单元格相同的值(活动)

时间:2014-07-28 13:03:30

标签: excel-vba vba excel

我正在制作一个宏,在1张纸上插入一行,然后在所有纸张中插入此行,但单独的列应引用常规纸张的值。 例如: 我有3张纸和一张模板。 然后我想运行一个宏,在模板表中插入一些带有一些值的行。 并且循环遍历所有3张纸将该行插入同一位置,然后是困难的部分,它提供了到模板表单元格的活动链接。

因此,当有人刚刚更改模板上1个单元格的值时,此值会在所有不同的选项卡上更改。

我有这个,但这不是一个活动链接,它只设置该时间值的状态,我找不到使其成为活动参考的语法。

    For Each Current In Worksheets
        Current.Cells(startCell.Row, startCell.Column).Offset(1).EntireRow.Insert
        Current.Cells(rowNumber + 1, 1).Value = ws.Cells(rowNumber + 1, 1).Value
        Current.Cells(rowNumber + 1, 2).Value = ws.Cells(rowNumber + 1, 2).Value
        Current.Cells(rowNumber + 1, 2).Borders.LineStyle = xlContinuous
        Current.Cells(rowNumber + 1, 3).Value = ws.Cells(rowNumber + 1, 3).Value
        Current.Cells(rowNumber + 1, 3).Borders.LineStyle = xlContinuous
        Current.Cells(rowNumber + 1, 4).Value = ws.Cells(rowNumber + 1, 4).Value
        Current.Cells(rowNumber + 1, 4).Borders.LineStyle = xlContinuous
        Current.Cells(rowNumber + 1, 5).Value = ws.Cells(rowNumber + 1, 5).Value
        Current.Cells(rowNumber + 1, 5).Borders.LineStyle = xlContinuous
    Next Current

我一直在寻找正确的语法,以编程方式创建这样的链接一段时间,我找不到任何有用的东西。

提前致谢。

1 个答案:

答案 0 :(得分:0)

我一直在寻找的是:

    'First get the address you need from that cell
    testString = Range(Cells(2, 2), Cells(2, 2)).Address 
    'Add the = in front of the address
    ActiveSheet.Cells(1, 1) = "=" & testString

但是我无法写出我需要的内容以及我提供的解决方案,但编码不好。 如果有人有更好的解决方案,那就太好了......