Macro to put value into cell when click another cell

smiley3141

Board Regular
Joined
Aug 13, 2010
Messages
77
Hello.

I am using Excel 2007 and I have a small chart with column and row headings. I would like to create a macro that inputs data into other cells depending on what cell in the chart I click. I would also like to clear the names when I select another cell.

My data's column headings are in cells B6:K6 and they are collectively named "People_Owed". The row headers are in cells A7:A16 and they are collectively named "People_Paid." The cells are B7:K16 make up the rest of the chart and those cells are collectively named "Money_Owed". I would like to be able to click a cell in the "Money_Owed" section and have the Person paid put into Cell A1 and the Person owed put into cell A2.

Also, I would like to be able to click in cell A6 and have the values in cell A1 and A2 be cleared.

Is there some way to do this?

I appreciate any help you can give me.
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Maybe this

Right-click on the sheet tab, pick View code and paste the code below in the right-panel

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    
    If Not Intersect(Target, Range("B7:K16")) Is Nothing Then
        Range("A1") = Cells(Target.Row, 1)
        Range("A2") = Cells(6, Target.Column)
    End If
    
    If Not Intersect(Target, Range("A6")) Is Nothing Then
        Range("A1") = ""
        Range("A2") = ""
    End If
    
End Sub

M.
 
Upvote 0

Forum statistics

Threads
1,223,911
Messages
6,175,337
Members
452,637
Latest member
Ezio2866

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top