Connecting macros to buttons

123Maximus

New Member
Joined
Dec 31, 2016
Messages
13
Hello!

In Excel I have created some rectangles as buttons to which I want to connect macros.
Every time I click a 'button' it should send a certain word to an emty cell in column A (starting with A1).

I tried to record a macro and changed Range("A1") to "A" but it didn't work.

Sub Makro3()
'
' Macro3 Macro
' Sends the text Shoes
'
Range("A").Select
ActiveCell.FormulaR1C1 = "Shoes"
Range("A").Select
End Sub

My intention is to collect all the words in column A for further processing later.

Can anybody help me?

Thanks in advance and a Happy New Year!
 

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
123Maximus,

Maybe this is what you are wanting...

Code:
Sub Makro3()
'
' Macro3 Macro
' Sends the text Shoes
'Find next available row in column A
r = Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & r) = "Shoes"
Range("A" & r).Select
End Sub

Hope that helps.
 
Upvote 0
Try this:

This script will paste the active cell value below the last filled row in column "A"
Code:
Sub Test()
Application.ScreenUpdating = False
Dim i As Long
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row + 1
ActiveCell.Copy Destination:=Range("A" & Lastrow)
Application.ScreenUpdating = True
End Sub
 
Last edited:
Upvote 0
Hello!
It worked!
I also created new 'buttons' with other words and put it after the first code (changing the name to Macro 4 and so on).

Thank you very much and a I wish you a Happy New Year!
 
Upvote 0
I assumed you are wanting to send a specific word for a given button ?
M A I T has assumed you are sending the word from the active cell ?
One of us is wrong:)

If it is a specific word per button and that word is the text of that button then you could use the below for all buttons

Code:
Sub Makro3()
' Sends the text that is on the button ????
'Find next available row in column A
r = Cells(Rows.Count, "A").End(xlUp).Row + 1
Range("A" & r) = ActiveSheet.Shapes(Application.Caller).TextFrame.Characters.Text
Range("A" & r).Select
End Sub
 
Upvote 0
Hello Tony!
Your first suggestion was what I was looking for, and it worked.
However, your second solution makes it much more easier to use because I have fifteen buttons to take care of.

Thanks once again!

/Håkan
 
Upvote 0
Hello again!

What code do I need to send a number instead of a text from a button, so I can make simple calculations?
Does it work with negative values too?

Or, any suggestions how to create a "Undo button" e. g ctrl-Z to reverse wrong inputs.

This cash register are going to be used by 'technical idiots' so it has to be fool proof... :LOL:
 
Upvote 0
The procedure receives whatever is in the text of that rectangular. So if there's number - you'll get number :LOL:
 
Upvote 0

Forum statistics

Threads
1,214,798
Messages
6,121,630
Members
449,041
Latest member
Postman24

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