Target.Formula包含一个单元格引用。如何获得旁边的单元格引用?

时间:2018-12-06 16:53:26

标签: excel vba excel-vba

我通过编辑-中的第1列激活了一个宏。 -thisSheet

Private Sub Worksheet_Change(ByVal Target As Range)
    If Target.Column = 1 Then
        MsgBox (Target.Formula)
    End If
End Sub

例如编辑thisSheet!A$1后,消息框显示=otherSheet!C$123很好

现在,我需要宏自动将thisSheet!B$1公式写入otherSheet!D$123。简而言之,我想将otherSheet中一行的单元格引用输入到thisSheet行中 这是我需要的一个小例子

步骤1,otherSheet为常量,thisSheet为空。

otherSheet                   thisSheet
---+-------+-------+-------  -+-----------------+-----------------+-----------------
   | C     | D     | E        | A               | B               | C
---+-------+-------+-------  -+-----------------+-----------------+-----------------
123|valueA1|valueB1|valueC1  1|                 |                 |
---+-------+-------+-------  -+-----------------+-----------------+-----------------
124|valueA2|valueB2|valueC2  2|                 |                 |
---+-------+-------+-------  -+-----------------+-----------------+-----------------

第2步,otherSheet是常量,thisSheet是手动编辑的

otherSheet                   thisSheet
---+-------+-------+-------  -+-----------------+-----------------+-----------------
   | C     | D     | E        | A               | B               | C
---+-------+-------+-------  -+-----------------+-----------------+-----------------
123|valueA1|valueB1|valueC1  1|=otherSheet!C$123|                 |
-+-------+-------+-------    -+-----------------+-----------------+-----------------
124|valueA2|valueB2|valueC2  2|                 |                 |
-+-------+-------+-------    -+-----------------+-----------------+-----------------

第3步,otherSheet是常量,thisSheet由宏自动编辑

otherSheet                   thisSheet
---+-------+-------+-------  -+-----------------+-----------------+-----------------
   | C     | D     | E        | A               | B               | C
---+-------+-------+-------  -+-----------------+-----------------+-----------------
123|valueA1|valueB1|valueC1  1|=otherSheet!C$123|=otherSheet!D$123|=otherSheet!E$123
---+-------+-------+-------  -+-----------------+-----------------+-----------------
124|valueA2|valueB2|valueC2  2|                 |                 |
---+-------+-------+-------  -+-----------------+-----------------+-----------------

该怎么做?

1 个答案:

答案 0 :(得分:1)

您可以执行此操作。但是,您是说每次更改A时都想将其复制到另一列吗?还是由什么决定范围?

#!/bin/bash
file=$(cat /tmp/testmonitor.txt)
if [[ $file == $file ]]; then  
     echo "files match"   
else  
    echo "files not matching"  
fi