bluewaterfree
New Member
- Joined
- Dec 6, 2020
- Messages
- 20
- Office Version
- 2019
- Platform
- Windows
Here's my code....
'REQUIRE ALL VARIABLES TO BE DECLARED
Option Explicit
'
' THIS MODULE CONTAINS MACROS ASSOCIATED WITH THE FINANCIALDISCLOSURE USERFORM
'
'
'......................................................................................................................................
'......................................................................................................................................
Private Sub UserForm_Initialize()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
Dim i As Long ' Loop Counter
'
'......................................................................................................................................
With FinancialDisclosureUserForm
.SelectedMonth.Clear
.SelectedYear.Clear
.Label1.Font.Size = 12
.Label2.Font.Size = 12
For i = 1 To 12
SelectedMonth.AddItem (i) ' Add the month numbers to the Combo Box SelectedMonth
Next
SelectedMonth.AddItem ("Exit") ' Finally, add "Exit" to the Combo Box to allow user to exit
For i = 2020 To 2025
SelectedYear.AddItem (i) ' Add the year numbers to the Combo Box SelectedYear
Next
SelectedYear.AddItem ("Exit") ' Finally, add "Exit" to the Combo Box to allow user to exit
End With
End Sub
Private Sub SelectedMonth_Change()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
'......................................................................................................................................
If SelectedMonth.Text = "Exit" Then End ' If "Exit" was selected, quit the macro
Range("Q1").Value = "Monthly" ' Set cell Q1 to Report Type
Range("Q2").Value = SelectedMonth.Text ' Set cell Q1 to Report Parameter
Range("L1").Value = SelectedMonth.Text ' Set Month in Pivot Table
Range("L2").Value = "2020" ' Set Year in Pivit Table
FinancialDisclosureUserForm.Hide
End Sub
Private Sub SelectedYear_Change()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
'......................................................................................................................................
If SelectedYear.Text = "Exit" Then End ' If "Exit" was selected, quit the macro
Range("Q1").Value = "Annual" ' Set cell Q1 to Report Type
Range("Q2").Value = SelectedYear.Text ' Set cell Q1 to Report Parameter
Range("L1").Value = "(All)" ' Set Month in Pivot Table
Range("L2").Value = SelectedYear.Text ' Set Year in Pivit Table
FinancialDisclosureUserForm.Hide
End Sub
First routine is the Initialization... as you can see the very first to lines are .SelectedMonth.Clear and .SelectedYear.Clear.... the names of the two Combo Boxes on UserForm FinancialDisclosureUserForm.
First time I run it, it works perfectly. The combo boxes load with blank showing... and the list I create below that. I select either a Month or a Year from the respective drop down... it then executes the proper report... life is great.
Second time I run it... the user form comes back with the previously selected value already selected?!?!?!?! What the? If I select a different value... it again executes the new report correctly.... but the old values are "retained"...
After a run, how do I get it to go back to showing "blank"... nothing selected?? My code "works" ... but it looks weird to have those old values being displayed.
Please and thanks.
Mark
'REQUIRE ALL VARIABLES TO BE DECLARED
Option Explicit
'
' THIS MODULE CONTAINS MACROS ASSOCIATED WITH THE FINANCIALDISCLOSURE USERFORM
'
'
'......................................................................................................................................
'......................................................................................................................................
Private Sub UserForm_Initialize()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
Dim i As Long ' Loop Counter
'
'......................................................................................................................................
With FinancialDisclosureUserForm
.SelectedMonth.Clear
.SelectedYear.Clear
.Label1.Font.Size = 12
.Label2.Font.Size = 12
For i = 1 To 12
SelectedMonth.AddItem (i) ' Add the month numbers to the Combo Box SelectedMonth
Next
SelectedMonth.AddItem ("Exit") ' Finally, add "Exit" to the Combo Box to allow user to exit
For i = 2020 To 2025
SelectedYear.AddItem (i) ' Add the year numbers to the Combo Box SelectedYear
Next
SelectedYear.AddItem ("Exit") ' Finally, add "Exit" to the Combo Box to allow user to exit
End With
End Sub
Private Sub SelectedMonth_Change()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
'......................................................................................................................................
If SelectedMonth.Text = "Exit" Then End ' If "Exit" was selected, quit the macro
Range("Q1").Value = "Monthly" ' Set cell Q1 to Report Type
Range("Q2").Value = SelectedMonth.Text ' Set cell Q1 to Report Parameter
Range("L1").Value = SelectedMonth.Text ' Set Month in Pivot Table
Range("L2").Value = "2020" ' Set Year in Pivit Table
FinancialDisclosureUserForm.Hide
End Sub
Private Sub SelectedYear_Change()
' Used in Financial Disclosure to convert investment data into 278e and 278t Financial Disclosure Reports
' Initiated by Financial DIsclosure Button on Ribbon
'
'......................................................................................................................................
If SelectedYear.Text = "Exit" Then End ' If "Exit" was selected, quit the macro
Range("Q1").Value = "Annual" ' Set cell Q1 to Report Type
Range("Q2").Value = SelectedYear.Text ' Set cell Q1 to Report Parameter
Range("L1").Value = "(All)" ' Set Month in Pivot Table
Range("L2").Value = SelectedYear.Text ' Set Year in Pivit Table
FinancialDisclosureUserForm.Hide
End Sub
First routine is the Initialization... as you can see the very first to lines are .SelectedMonth.Clear and .SelectedYear.Clear.... the names of the two Combo Boxes on UserForm FinancialDisclosureUserForm.
First time I run it, it works perfectly. The combo boxes load with blank showing... and the list I create below that. I select either a Month or a Year from the respective drop down... it then executes the proper report... life is great.
Second time I run it... the user form comes back with the previously selected value already selected?!?!?!?! What the? If I select a different value... it again executes the new report correctly.... but the old values are "retained"...
After a run, how do I get it to go back to showing "blank"... nothing selected?? My code "works" ... but it looks weird to have those old values being displayed.
Please and thanks.
Mark