How to populate a cell[s] by clicking on another cell

liemaj

New Member
Joined
Oct 22, 2019
Messages
5
Hi all,

1st post here. I want to cells to populate with "Y" when someone clicks on another cell in a worksheet. Is this possible within excel? If so, could someone assist.

Example, someone clicks on cell A1 then cells A2, A3, A4, A5 etc. are populated with Y.

Thanks.
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Hi all,

1st post here. I want to cells to populate with "Y" when someone clicks on another cell in a worksheet. Is this possible within excel? If so, could someone assist.

Example, someone clicks on cell A1 then cells A2, A3, A4, A5 etc. are populated with Y.

Thanks.
Try this sheet event code.

To install sheet code:
1. Right-click the worksheet tab you want to apply it to and choose 'View Code'. This will open the VBE window.
2. Copy the code below from your browser window and paste it into the white space in the VBE window.
3. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
4. Make sure you have enabled macros whenever you open the file or the code will not run.
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
    Range("A2:A5").Value = "Y"
End If
End Sub
 
Upvote 0
Try this sheet event code.

To install sheet code:
1. Right-click the worksheet tab you want to apply it to and choose 'View Code'. This will open the VBE window.
2. Copy the code below from your browser window and paste it into the white space in the VBE window.
3. Close the VBE window and Save the workbook. If you are using Excel 2007 or a later version do a SaveAs and save it as a macro-enabled workbook (.xlsm file extension).
4. Make sure you have enabled macros whenever you open the file or the code will not run.
Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Not Intersect(Target, Range("A1")) Is Nothing Then
    Range("A2:A5").Value = "Y"
End If
End Sub

This works, thank you very much!
 
Upvote 0
You are welcome - thanks for the reply.

Hello! Me again, so i've been playing around with your code. I was hoping I could easily figure out how to do this, but it's proving harder than I envisaged.

So I basically want to be able to replicate the code above for multiple columns in a worksheet i.e. if I click A1, populate A2, A3, A4 etc with Y, if I click B1 populate B2, B3, B4 etc.

Apologies if this is basic, but i am very, very new to VBE.
 
Upvote 0
The following code will update rows 2-5 in any column with "Y" whenever a single column in row 1 is selected:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Rows("1:1")) Is Nothing Then
    Range(Cells(2, Target.Column), Cells(5, Target.Column)).Value = "Y"
End If
End Sub
 
Upvote 0
The following code will update rows 2-5 in any column with "Y" whenever a single column in row 1 is selected:
Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Target.CountLarge > 1 Then Exit Sub
If Not Intersect(Target, Rows("1:1")) Is Nothing Then
    Range(Cells(2, Target.Column), Cells(5, Target.Column)).Value = "Y"
End If
End Sub

Yup, this works! Thanks for the quick response.
 
Upvote 0
You are welcome.
Glad us "Joes" were able to help!;)
 
Last edited:
Upvote 0

Forum statistics

Threads
1,213,531
Messages
6,114,172
Members
448,554
Latest member
Gleisner2

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