2013-04-04 73 views
0

我有2個文件sit.xls和plan.xls。 在sit.xls想要在2個Excel文件之間傳輸數據

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. 
+0

真的不清楚你到底想要達到什麼目的。當你點擊什麼 - 第三行的任何單元格? - 你想要什麼轉移到其他電子表格? – Vicky 2013-04-04 13:23:24

+0

我想要當我點擊rollno(例如5659724或任何卷no)在sit.xls它會自動轉移到plan.xls其中也包含rollno – vihaan 2013-04-04 17:01:10

回答

0

你可以寫上一個選擇VBA代碼在sit.xls中更改事件如下。下面的代碼將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 
+0

嗨非常感謝但它給運行時錯誤9下標如果範圍 – vihaan 2013-04-08 08:34:18