简体   繁体   中英

In excel how do i make cells in a column/row clickable?

In excel how do i make cells in a column/row clickable? I have a data grid and want to be able to click on a cell in column N and have that data in that cell appear in another cell. I also want to be able to click on a cell in row 3 and have that data appear in a second cell. (Table begins at column N and row 3)

Here is a method for double click

Enter the following event macro in the worksheet code area:

Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Dim Reg As Range, B2 As Range
    Set Reg = Union(Cells(1, 1).EntireRow, Cells(1, 1).EntireColumn).Cells
    Set B2 = Range("B2")
    If Intersect(Target, Reg) Is Nothing Then Exit Sub
    Cancel = True
    B2.Value = Target.Value
End Sub

If you double click on a cell in column A or row#1, its value will appear in cell B2

Because it is worksheet code, it is very easy to install and automatic to use:

  1. right-click the tab name near the bottom of the Excel window
  2. select View Code - this brings up a VBE window
  3. paste the stuff in and close the VBE window

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:

  1. bring up the VBE windows as above
  2. clear the code out
  3. close the VBE window

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!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM