I’m trying to setup a cell with the contents of whatever is in the “A” column of the row with any cell selected in that row.
ie: cell D3 would return the contents of A34 for any cell selected in row 34.
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
Home » Forums » AskWoody support » Productivity software by function » MS Excel and spreadsheet help » selection VBA
Right-click the sheet tab and enter or copy the following code:
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) Range("D3") = Range("A" & ActiveCell.Row) End Sub
Hi. How could this code be modified to make it so I can apply this concept to a range of cells?
For example, if I have cells B3:H14 that I want to apply this code to so that if I select cell B5 it gives me the value in A5, if I select cell D13 it gives me the value in A13, etc.
And to complicate it, only one cell (in the range B3:H14) in any of the columns should have a value in it. So if I select B3 it has a value equal to A3, but then if I select B6 it has a value equal to A6 and B3 now has no value.
Any help is greatly appreciated.
Thanks,
Brett
Does this do what you want?
Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Range("B3:H14"), ActiveCell) Is Nothing Then Range(Cells(3, ActiveCell.Column), Cells(14, ActiveCell.Column)).ClearContents ActiveCell = Cells(ActiveCell.Row, 1) End If End Sub
Does this do what you want?
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Range("B3:H14"), ActiveCell) Is Nothing Then Range(Cells(3, ActiveCell.Column), Cells(14, ActiveCell.Column)).ClearContents ActiveCell = Cells(ActiveCell.Row, 1) End If End Sub
I cannot find any technique to trigger an event when activating the next cell within a selected range by tabbing. Is it possible?
Does this do what you want?
Code:Private Sub Worksheet_SelectionChange(ByVal Target As Range) If Not Intersect(Range("B3:H14"), ActiveCell) Is Nothing Then Range(Cells(3, ActiveCell.Column), Cells(14, ActiveCell.Column)).ClearContents ActiveCell = Cells(ActiveCell.Row, 1) End If End Sub
That does exactly what I want. Thanks so much!!!
-Brett
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.
Notifications