Reference VBA code in new event

tjdickinson

Board Regular
Joined
Jun 26, 2021
Messages
61
Office Version
  1. 365
Platform
  1. Windows
Hi, all, I'm new to VBA coding and, of course, trying an ambitious project (creating my own gradebook in Excel). I haven't got the time to go through an entire VBA course, so I'm turning to the experts for help. While I have a bit of general coding experience (mostly HTML), I'm an absolute novice at VBA, so please forgive my inaccuracies.

The first question is this:
I have a userform with three buttons: 'Add_Eval_Add' (adds the evaluation, then clears the form so a new evaluation can be added), 'Add_Eval_Close' (adds the evaluation, then closes the form), 'Cancel_New_Eval' (closes the form without adding an evaluation). The buttons are coded and working as expected.

The code for 'Add_Eval_Close' is, however, copied and pasted from 'Add_Eval_Add', with the additional line 'Unload Me' tacked on the bottom. I would like, instead, to have this button reference the code for 'Add_Eval_Add', and then run the 'Unload Me' command, so that I only need to make changes in one part of the code. So, something like:

VBA Code:
Private Sub Add_Eval_Close_Click ()
Run Add_Eval_Add_Click ()
Unload Me
End Sub

Any ideas?
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Try
VBA Code:
Private Sub Add_Eval_Close_Click ()
Me.Add_Eval_Add_Click ()
Unload Me
End Sub
 
Upvote 0
Try
VBA Code:
Private Sub Add_Eval_Close_Click ()
Me.Add_Eval_Add_Click ()
Unload Me
End Sub
Thanks! But I get this error message:
Compile error: Syntax error

When I click OK, it highlights the line "Private Sub Add_Eval_Close_Click ()" in yellow with a little yellow arrow next to it, and the line "Me.Add_Eval_Add_Click ()" has red text.
 
Upvote 0
Hi,
try

VBA Code:
Private Sub Add_Eval_Close_Click()
    Call Add_Eval_Add_Click
    Unload Me
End Sub

Dave
 
Upvote 0
Solution

Forum statistics

Threads
1,224,936
Messages
6,181,851
Members
453,068
Latest member
DCD1872

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