Slow response to execute VBA code using buttons

PPriest

New Member
Joined
Jun 11, 2018
Messages
36
Due to the complexity of a data entry page, I scrapped my userform and went to an excel sheet for data entry. It has over 200 buttons so that the user can click and go. All of the buttons are linked to code this simple:

Sub Mcn1()
ActiveSheet.Range("AR2").Value = ActiveSheet.Range("Q5").Value
End Sub

The first few buttons worked super fast and snappy but as I continue to add buttons, the slower it gets to respond when a button is pressed (several seconds each). If I open the developer and screen (Alt+F11), and run the code, it's nearly instantaneous. I am assuming that the more macros I add, the slower it takes to find and run the macro assigned to each button. Would I be incorrect in that assumption? If so - how do I fix that? Any other suggestions on creating a user form where the user only has to select what they want and the code populates to the data entry section?
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.
The way I would do that is to use the Worksheet_BeforeDoubleClick event, so the user just double clicks on each cell that they want to copy, you then create a mapping table which maps the address of the double clicked cell to where you want to put it. I would put mapping on a another Veryhidden worksheet which I would load into a variant array when you select the sheet, this would mean no buttons ie more space on the worksheet, only one very simple macro, and easily modified by changing the mapping table without needing to change the macro at all.
 
Upvote 0
Solution
The way I would do that is to use the Worksheet_BeforeDoubleClick event, so the user just double clicks on each cell that they want to copy, you then create a mapping table which maps the address of the double clicked cell to where you want to put it. I would put mapping on a another Veryhidden worksheet which I would load into a variant array when you select the sheet, this would mean no buttons ie more space on the worksheet, only one very simple macro, and easily modified by changing the mapping table without needing to change the macro at all.
Thank you for your response. This solves my issue on speed - thank you! I hadn't used this method before so it was a great lesson learned. Appreciate it!

Due to my desire to reduce the number of required inputs from the users, I wanted to do the same thing without the required second click. I did some further digging based upon what you presented and have chosen to use this method:

Option Explicit

Private Sub Worksheet_SelectionChange(ByVal Target As Range)
If Selection.Count = 1 Then

If Not Intersect(Target, Range("P5")) Is Nothing Then
ActiveSheet.Range("AR2").Value = ActiveSheet.Range("Q5").Value
GoTo Finish
End If

End If

Finish:
End Sub


Found at: How to trigger or run a Macro by clicking a specific cell in Excel?
 
Upvote 0

Forum statistics

Threads
1,214,982
Messages
6,122,580
Members
449,089
Latest member
Motoracer88

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