Macro to fill in cells from a column sequentially when I click on a button

Mary_z

New Member
Joined
Feb 20, 2015
Messages
4
Hello.
I'm have a lot of trouble trying to figure this out.

This is my layout:



As you can see, I have 2 buttons.
What I would like each button to do is:
1. Each time I click on YES, it will insert a Y in a cell in a specific range.
2. If I click on YES again, it will automatically insert a Y in the next cell under the previous one in the same column.
3. As you can see, if I have to click on NO, it will also continue down the column and insert an N.


If someone can help me out with this I'd be very grateful!
 
Last edited:

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
something like (for the "Yes" option)

targetrw = Range("m" & Rows.Count).End(xlUp).Row + 1
Range("m" & targetrw) = "Y"
 
Upvote 0
The code for can be written as easily as:

Code:
Sub YesButton()

    ActiveCell.Value = "Y"
    ActiveCell.Offset(1, 0).Select

End Sub

Sub NoButton()

    ActiveCell.Value = "N"
    ActiveCell.Offset(1, 0).Select

End Sub

You could add those codes to a standard module (from the VBA window, insert module, and paste it into the resulting window). From the spreadsheet, in Design Mode, right-click each button, and assign the applicable macro. Get out of Design Mode, click on the first blank cell in your column, and start clicking your buttons.

You could write this more slickly (the code needn't be in a public module, you could write some extra code to find the first blank cell, etc), but this is the nuts-and-bolts of it.
 
Upvote 0
See: SteveO59L, more slick. You can replace his code with my ActiveCell statements in the YesButton code, and that finds the blank cell, rather than moving your selections around the spreadsheet (generally bad form).
 
Upvote 0
Thanks SteveO59L and tapedeck
I tried it on a blank excel sheet and it works fine.
The issue I'm having now is that I need it to start at AS11 to AS500 on the sheet I'm currently working on which has a lot of stuff on it.

I tried this:
Code:
targetrw = Range(as11, [as500] & Rows.Count).End(x1Up).Row + 1
Range(as11, [as500] & targetrw) = "Y"

I get no error, but nothing is being inserted. :confused:

EDIT, I also just tried using the column AS (no range) but still nothing comes up.
Could another macro on this sheet be interfering?
 
Last edited:
Upvote 0
Hi,
see if this slight modification to SteveO59L suggestion helps you:

Code:
targetrw = Range("AS" & Rows.Count).End(xlUp).Row + 1
If targetrw < 11 Then targetrw = 11
If targetrw <= 500 Then Range("AS" & targetrw) = "Y"

Dave
 
Upvote 0
Hi,
see if this slight modification to SteveO59L suggestion helps you:

Code:
targetrw = Range("AS" & Rows.Count).End(xlUp).Row + 1
If targetrw < 11 Then targetrw = 11
If targetrw <= 500 Then Range("AS" & targetrw) = "Y"

Dave

That worked PERFECTLY, Dave!!!
Many thanks! :biggrin:
 
Upvote 0

Forum statistics

Threads
1,215,261
Messages
6,123,931
Members
449,134
Latest member
NickWBA

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