putting a value in a formula based on what cell is "clicked" -- Excel 2010

Experts,

I would like to create an Interactive spreadsheet (see attached workbook), where if you click on any "A2 through A8" the value in that field will be used in the compare in H5 where "12345" is currently coded.

Can someone tell me how to do this?
Sample-XlS.xlsx
moriniaAdvanced Analytics AnalystAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
As formulas can't tell which cell is currently selected, you'll need to use VBA.

The code below gets pasted into the worksheets code module (right-click tab and select "View Code")...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)    
    If Not Intersect(Target, [A2:A8]) Is Nothing Then
        Range("H5").Formula = "=SUMIFS(orders,FIELDA," & Target.Value & ")"
    End If    
End Sub

Open in new window


This will modify the formula in cell H5 whenever you select a cell in the range A2:A8.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
moriniaAdvanced Analytics AnalystAuthor Commented:
Wayne,

Is there a way to put just the value of the selected cell into H5 so I can use it for other things also.
I think I did this before but don't have access to the spreadsheet anymore  

The formula then uses the cake in H5.
Wayne Taylor (webtubbs)Commented:
Yes, use this instead...

Private Sub Worksheet_SelectionChange(ByVal Target As Range)    
    If Not Intersect(Target, [A2:A8]) Is Nothing Then
        Range("H5").Value = Target.Value
    End If    
End Sub

Open in new window

Rob HensonFinance AnalystCommented:
It is possible with formula as well.

In the cell where you want the specific value use formula:

=INDIRECT(ADDRESS(CELL("row"),CELL("col"),1,1))

initially this will give a Circular Reference but when you enter a value in another cell, on recalculation the cell with the formula will also get that value.

Thanks
Rob H
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.