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.
 

JoeMo

MrExcel MVP
Joined
May 26, 2009
Messages
16,666
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
 

liemaj

New Member
Joined
Oct 22, 2019
Messages
5
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!
 

liemaj

New Member
Joined
Oct 22, 2019
Messages
5
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,482
Office Version
365
Platform
Windows
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
 

liemaj

New Member
Joined
Oct 22, 2019
Messages
5
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.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
51,482
Office Version
365
Platform
Windows
You are welcome.
Glad us "Joes" were able to help!;)
 
Last edited:

Forum statistics

Threads
1,082,065
Messages
5,362,976
Members
400,702
Latest member
oliviaalx

Some videos you may like

This Week's Hot Topics

  • populate from drop list with multiple tables
    Hi All, i have a drop list that displays data, what i want is when i select one of those from the list to populate text from different tables on...
  • Find list of words from sheet2 in sheet1 before a comma and extract text vba
    Hi Friends, Trying to find the solution on my task. But did not find suitable one to the need. Here is my query and sample file with details...
  • Dynamic Formula entry - VBA code sought
    Hello, really hope one of you experts can help with this - i've spent hours on this and getting no-where. .I have a set of data (more rows than...
  • Listbox Header
    Have a named range called "AccidentsHeader" Within my code I have: [CODE]Private Sub CommandButton1_Click() ListBox1.RowSource =...
  • Complex Heat Map using conditional formatting
    Good day excel world. I have a concern. Below link have a list of countries that carries each country unique data. [URL...
  • Conditional formatting
    Hi good morning, hope you can help me please, I have cells P4:P54 and if this cell is equal to 1 then i want row O to say "Fully Utilised" and to...
Top