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

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,700
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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

My Aswer Is This

Well-known Member
Joined
Jul 5, 2014
Messages
19,343
Office Version
  1. 2021
Platform
  1. Windows
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

123Maximus

New Member
Joined
Dec 31, 2016
Messages
13
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

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,700
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
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

123Maximus

New Member
Joined
Dec 31, 2016
Messages
13
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

Snakehips

Well-known Member
Joined
May 17, 2009
Messages
5,700
Office Version
  1. 365
  2. 2010
Platform
  1. Windows
Great. Thanks for the feedback.
 
Upvote 0

123Maximus

New Member
Joined
Dec 31, 2016
Messages
13
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

Sektor

Well-known Member
Joined
May 6, 2011
Messages
2,874
Office Version
  1. 365
Platform
  1. Windows
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,190,962
Messages
5,983,873
Members
439,868
Latest member
Shadrack

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
Top