Reference VBA code in new event

tjdickinson

New Member
Joined
Jun 26, 2021
Messages
17
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

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

EFANYoutube

Active Member
Joined
May 19, 2017
Messages
278
Try
VBA Code:
Private Sub Add_Eval_Close_Click ()
Me.Add_Eval_Add_Click ()
Unload Me
End Sub
 

tjdickinson

New Member
Joined
Jun 26, 2021
Messages
17
Office Version
  1. 365
Platform
  1. Windows
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.
 

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,790
Office Version
  1. 2019
Platform
  1. Windows
Hi,
try

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

Dave
 
Solution

Forum statistics

Threads
1,140,999
Messages
5,703,639
Members
421,307
Latest member
morrden86

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