Returning value of top row of active cell

Damo71

Board Regular
Joined
Aug 17, 2010
Messages
88
Hi

When I select a cell, how do I programmatically, in Cell A1, return the value of the third row in whatever column the current selection is? (it will never be in column A)

E.g. H3 contains the value "Pickles". When I select H15 (or any other row in H), cell A1 will return "Pickles".

However if the current selection is in Row 3, the macro doesn't run

thanks
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Try an if statement before returning values.

For example;

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
   If ActiveCell.Row <> 3 Then[COLOR=#333333]
[/COLOR]      Cells(1, 1).Value = Cells(3, ActiveCell.Column).Value
   Else
       'Do nothing maybe? Or else?
   End If
End Sub

But in my opnion only
Code:
Cells(1, 1).Value = Cells(3, ActiveCell.Column).Value
line should be enough
 
Last edited by a moderator:
Upvote 0
Another option
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)

   If Target.CountLarge > 1 Then Exit Sub
   If Not Target.row = 3 And Not Target.column = 1 Then
      Range("A1").Value = Cells(3, Target.column).Value
   End If

End Sub
This prevents any problems incase more than 1 cell is selected.
 
Upvote 0

Forum statistics

Threads
1,223,920
Messages
6,175,373
Members
452,638
Latest member
Oluwabukunmi

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