Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Display values in Excel based on the location of the current active cell

Posted on 2011-02-14
7
269 Views
Last Modified: 2012-05-11
Hello,

In Excel (2007), what formula or code would enable a given cell to display values from a range based on the location of the current active cell?

For example, suppose column A contains arbitrary values in all cells from row 1 to row 9999 (A1:A9999) and you want to be able to activate or select (by clicking or using arrow keys, etc.) any corresponding cell in column B (in range B1:B9999) and have cell C1 display the value from the adjacent cell in column A.

In other words:

    if cell B1 is active, cell C1 will display the value in A1.
    if cell B2 is active, cell C1 will display the value in A2.
    if cell B3 is active, cell C1 will display the value in A3.
    if cell B4 is active, cell C1 will display the value in A4.
    and so on...

In effect, it would be very similar to how the Name Box, in the upper left corner of Excel, displays the coordinates for the currently active cell, except here, C1 would be displaying the values from the same row in column A.

By the way, if more than one cell in column B is selected, C1 should display the value from the first corresponding column A cell -- again similar to how the Name Box works.

Thanks
0
Comment
Question by:Steve_Brady
  • 3
  • 2
  • 2
7 Comments
 
LVL 42

Expert Comment

by:dlmille
ID: 34890518
Put the following in ThisWorkbook codepage.

Dave
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        rowsel = Target.Row
        Range("C" & rowsel).Value = Range("A" & rowsel).Value
    End If
End Sub

Open in new window

0
 
LVL 42

Expert Comment

by:dlmille
ID: 34890533
Here it is attached.

PS - did you award points on that prior question?

Dave
ShowAinConBselect.xlsm
0
 
LVL 22

Assisted Solution

by:rspahitz
rspahitz earned 100 total points
ID: 34890601
I think this will work for you


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Column = 2 Then
        Range("C2").Value = Cells(Target.Row, 1).Value
    End If
End Sub


(dl, I think that the it's supposed to always be C1 and you put C + row#)
0
Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

 
LVL 42

Accepted Solution

by:
dlmille earned 400 total points
ID: 34890680
Good catch - here it is corrected with file...

Dave
Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)

    If Not Intersect(Target, Range("B:B")) Is Nothing Then
        rowsel = Target.Row
        Range("C1").Value = Range("A" & rowsel).Value
    End If
End Sub

Open in new window

ShowAinConBselect.xlsm
0
 

Author Closing Comment

by:Steve_Brady
ID: 35073071
Just what I needed!  Thanks
0
 

Author Comment

by:Steve_Brady
ID: 35073097
Tried to give rspahitz a few points for the heads up but it won't let me.  ??
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 35073174
looks like it worked...thanks Steve.
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
Workbook link problems after copying tabs to a new workbook? David Miller (dlmille) Intro Have you either copied sheets to a new workbook, and after having saved and opened that workbook, you find that there are links back to the original sou…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
The viewer will learn how to create a normally distributed random variable in Excel, use a normal distribution to simulate the return on an investment over a period of years, Create a Monte Carlo simulation using a normal random variable, and calcul…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question