Adding Macros to Buttons

Chrispydennis2

New Member
Joined
Feb 19, 2021
Messages
2
Office Version
  1. 365
Platform
  1. Windows
Hello, I’m fairly new to the excel game and I’m trying to build a schedule that is a little more user friendly for our meetings than what we are currently using.

This might be simple but I am struggling to get what I want.

I am wanting to add a button (Job 1) then I am wanting to click on the cell according to day and crew member. When I click the button I am wanting that job to duplicate to that cell.
A3136F41-3417-40F6-AB3D-A0E4AF68BE88.jpeg


For reference, I would want to click (job 1) than I would like to click any cell on the schedule E5- I 11 and that job name would appear in that cell. I’m sorry for the bad picture and the lazy excel creation, I just wanted to submit some form of visual. Thank you
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
I don't know about anyone else, but on my computer that picture is of such low quality I can't see what is what. Use a snipping tool or screen-grab tool instead of a photo.
 
Upvote 0
Try this in the sheet's module:
VBA Code:
Private Sub CommandButton1_Click()
    Dim r As Range
    Sheets(1).Activate
    On Error GoTo errhandler
    Set r = Application.InputBox("Select a cell to fill in with the job name.", "Fill", Type:=8)
    On Error GoTo 0
    If Intersect(r, Range("E5:I11")).Count = 1 Then
        r.Value = CommandButton1.Caption
    Else
        MsgBox "Selection out of range", vbExclamation, "Error"
    End If
Exit Sub
errhandler: 'Do nothing if selection is canceled
End Sub

Private Sub CommandButton2_Click()
    Dim r As Range
    Sheets(1).Activate
    On Error GoTo errhandler
    Set r = Application.InputBox("Select a cell to fill in with the job name.", "Fill", Type:=8)
    On Error GoTo 0
    If Intersect(r, Range("E5:I11")).Count = 1 Then
        r.Value = CommandButton2.Caption
    Else
        MsgBox "Selection out of range", vbExclamation, "Error"
    End If
Exit Sub
errhandler: 'Do nothing if selection is canceled
End Sub

Private Sub CommandButton3_Click()
    Dim r As Range
    Sheets(1).Activate
    On Error GoTo errhandler
    Set r = Application.InputBox("Select a cell to fill in with the job name.", "Fill", Type:=8)
    On Error GoTo 0
    If Intersect(r, Range("E5:I11")).Count = 1 Then
        r.Value = CommandButton3.Caption
    Else
        MsgBox "Selection out of range", vbExclamation, "Error"
    End If
Exit Sub
errhandler: 'Do nothing if selection is canceled
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,911
Messages
6,122,198
Members
449,072
Latest member
DW Draft

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