I want to be able to type into any cell in the worksheet and have it automatically copy to the second worksheet as I type. I know how I can copy from the current cell to another but I do not know how to do this live. I want to do this in VBA I know I can select both worksheets and just type but I want to do this in VBA.
Private Sub CommandButton1_Click()
Worksheets("Sheet1").Activate
ActiveCell.Copy
irow = ActiveCell.Row
icol = ActiveCell.Column
Worksheets("Sheet2").Cells(irow, icol).PasteSpecial xlPasteAll
End Sub
答案 0 :(得分:1)
Try this short event macro:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.EnableEvents = False
Target.Copy Sheets("Sheet2").Range(Target.Address)
Application.EnableEvents = True
End Sub
Because it is worksheet code, it is very easy to install and automatic to use:
If you have any concerns, first try it on a trial worksheet.
If you save the workbook, the macro will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx
To remove the macro:
To learn more about macros in general, see:
http://www.mvps.org/dmcritchie/excel/getstarted.htm
and
http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx
To learn more about Event Macros (worksheet code), see:
http://www.mvps.org/dmcritchie/excel/event.htm
Macros must be enabled for this to work!