Modify VBA Code To Run As Two Separate Macros to assign Shortcuts

im2bz2p345

Board Regular
Joined
Mar 31, 2008
Messages
229
Hi all,

I am an Excel 365 (32-bit) user that can't seem to get this bit of code to work properly after all sorts of effort.

Here is my current code:
VBA Code:
Public Sub Create_Shortcuts()

    'Ctrl + Shift + C
    Application.OnKey "^+C", "StoreSum"
    'Ctrl + Shift + V
    Application.OnKey "^+V", "PasteSum"

End Sub

Sub StoreSum()
Dim mySum As String

mySum = WorksheetFunction.Sum(Selection)

SaveSetting "SelectionSum", "Section1", "Key1", mySum

End Sub

Sub PasteSum()

ActiveCell.Value = GetSetting("SelectionSum", "Section1", "Key1")

End Sub

Instead of assigning a key combination using the Application.OnKey command, is it possible to split this up into two separate macros:
1. To copy the sum of numbers that I select
2. Paste-special that sum as values

I would somehow like for this to show up in the Macros windows when you press Alt + F8. Screenshot below.
SNAG_Program-0077.png

Any help would be greatly appreciate because I could not get this to work in my version of Excel as the code stands. Thank you!!

~ Im2bz2p345 :)
 

Excel Facts

Test for Multiple Conditions in IF?
Use AND(test, test, test, test) or OR(test, test, test, ...) as the logical_test argument of IF.
Hi, To assign a shortcut to already created procedures -

1. Go to Developer tab and click on Macro option.
2. Select Your first Subroutine (StoreSum) from the dropdown and click on Option button.
3. Enter your Shortcut Key in the box (press Shift+c) and click Ok.
4. Do the same steps for second Macro.
 
Upvote 0
Solution
Thank you Saurabhj,

I was initially trying to put the code in an Excel add-on, but that didn't seem to work. After enabling the add-on, for some reason, the subroutines wouldn't show up in the Macro key assignment window.

I now altered my startup Excel file called "Personal.xlsm" (in the directory C:\Users\User_name\AppData\Roaming\Microsoft\Excel\XLSTART) by adding only the code below into the Module1
VBA Code:
Sub StoreSum()
Dim mySum As String

mySum = WorksheetFunction.Sum(Selection)

SaveSetting "SelectionSum", "Section1", "Key1", mySum

End Sub

Sub PasteSum()

ActiveCell.Value = GetSetting("SelectionSum", "Section1", "Key1")

End Sub

Upon restarting Excel (which loads the Personal.xlsm file), I was then able to assign the appropriate shortcuts to the subroutines.

I wonder what caused the difference. Anyway, now it works fine. I marked you answer as the solution.

Appreciate your help,

~ Im2bz2p345 :)
 
Upvote 0
It's great that the problem is resolved. Thanks for sharing feedback.
 
Upvote 0

Forum statistics

Threads
1,223,247
Messages
6,171,007
Members
452,374
Latest member
keccles

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