0

我有 2 个文件 sat.xls 和 plan.xls。在sit.xls

Roll No.    Roll No.    Roll No.
10          11          12
5659694     5659724     5659754
5659695     5659725     5659755

我想当我点击 rollno(5659724) 时,它会自动传输或复制到 plan.xls 其中包含

ROW 1       ROW 2
ROLL NO.    ROLL NO.
4

1 回答 1

0

您可以在 sat.xls 中编写关于选择更改事件的 VBA 代码,如下所示。下面的代码将 plan.xls 中选定的单元格值复制到完全相同的位置。

  Private Sub Worksheet_SelectionChange(ByVal Target As Range)
     ' The variable for current cell value
     Dim currentValue As String
     ' The variable for current cell address
     Dim ActiveCellAddress As String
     'Get the value of the current cell from the current sheet Sit.xls
     currentValue = ActiveCell.FormulaR1C1
     'Get the address of the current cell from the current sheet Sit.xls
     ActiveCellAddress = ActiveCell.Address
     'Activate the another workbook Plan.xls
     Workbooks("Plan.xls").Activate
     'select the desired range
     Workbooks("Plan.xls").Sheets("Sheet1").Range(ActiveCellAddress).Select
     'Copy the value to the desired location
     ActiveCell.FormulaR1C1 = currentValue
     'Activate the old workbook again
     Workbooks("Sit.xls").Activate
  End Sub
于 2013-04-05T05:09:49.673 回答