I have 1 UserForm and want to save to different sheets in the same workbook

Ellendigitl00

New Member
Joined
Oct 23, 2024
Messages
6
Office Version
  1. 365
Platform
  1. Windows
Hello all,

I think this topic has been discussed in many posts here and other forums. I'm sorry for the Clickbait (for some), however, I was unable to solve my problem....

I have a workbook to register my expenses, so I have a Sheet for every month of the year: so, first sheet is for January, second sheet is for February and so on (Please see the attached image). All of them have the same formatting (basically I just copied each sheet and changed the name)...
To simplify the process (and also because I was curious about VBA Userforms), I created a UserForm to fill every expense in each month: so I have 3 TextBox to Expense Description; Date and expense value (in €) and a ComboBox to the category of expense.

My main issue is how can I save the Data in different sheets (for each month) using the same UserForm?
I believe I only need to change the code when appears "Worksheets ("Sheet name"), right?

Your help is much appreciated!
 

Attachments

  • Excel_expenses.png
    Excel_expenses.png
    20.7 KB · Views: 16

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
First, I would question why you want separate sheets per month? That will just make all your reporting harder.
 
Upvote 0
I chose to separate the sheets because for me it's easier to track my expenses. It's just a visual matter, I'm not interested in making a report. This is just for my personal expenses.
So, do you know how to save the data in different sheets using the same UserForm?
 
Upvote 0
There are many ways. The simplest would be to just use Activesheet rather than a specific sheet name, then make sure you activate the right sheet before loading the form. You could also add a listbox or combobox to allow you to select the relevant sheet name.
 
Upvote 0
There are many ways. The simplest would be to just use Activesheet rather than a specific sheet name, then make sure you activate the right sheet before loading the form. You could also add a listbox or combobox to allow you to select the relevant sheet name.
Yes, but that would make me do a different code for each sheet right?
Can you explain better that code, please?
 
Upvote 0
No, if the sheets are the same layout, then simply using activesheet rather than a specific sheet name should work.
 
Upvote 0
The code that I want to change is this one. The main goal is to order the Date from oldest to newest. You're saying that I only need to change the part that says ActiveWorkbook.Worksheets("OUT")?

Range("D5:G5").Select
Range(Selection, Selection.End(xlDown)).Select
ActiveWorkbook.Worksheets("OUT").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("OUT").Sort.SortFields.Add Key:=Range("F6:F27") _
, SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("OUT").Sort
.SetRange Range("D5:G27")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
 
Upvote 0
Yes, just change that to Activesheet.
 
Upvote 0
Code does not simply get ignored. If that code worked before, and you have the relevant sheet active, it will do what it did before unless there is some other code interfering (e.g. it activates a different sheet).
 
Upvote 0

Forum statistics

Threads
1,224,864
Messages
6,181,472
Members
453,045
Latest member
Abraxas_X

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