VBA - Click button populate a cell with the buttons caption and then move to the next cell

Tonkytonk

New Member
Joined
Apr 9, 2020
Messages
7
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Hi all,

I've been searching the internet for a couple of days and haven't quite found what I'm after and wondering if someone can help me out. My vba coding is horrendous and self taught over the last week.

What I've got is 15 different buttons what I want it to do is onclick for button1 which has a caption of A+ is to enter it in cell B7 then move on to select B8 then if I click on Button8 that has a caption of C to add that into cell b8. hopefully that makes sense. I've got a screenshot below with what the form looks like and sample code what I've done so far that is kinda doing what I want. What I want to achieve is hopefully only have 1 macro instead of 15 difference codes for each button.

You can also see with my current code is that it will only move to B7 and B8

VBA Code:
Sub A_Plus()
        Range("B7").Select
    If IsEmpty(ActiveCell) Then
        ActiveCell.Formula = "A+"
    Else
        ActiveCell.Offset(1, 0).Select
        ActiveCell.Formula = "A+"
    End If
    
End Sub

1586490075581.png


Thank you in advanced.
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
Hi and welcome to MrExcel.

is hopefully only have 1 macro instead of 15 difference codes for each button.

Assign the following macro to all buttons:

VBA Code:
Sub Populate_Cell()
  On Error Resume Next
  Range("B7:B11").SpecialCells(xlCellTypeBlanks).Cells(1).Select
  If Err.Number = 1004 Then
    MsgBox "There are no cells available"
  Else
    ActiveCell = ActiveSheet.DrawingObjects(Application.Caller).Caption
  End If
End Sub
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,805
Messages
6,121,664
Members
449,045
Latest member
Marcus05

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