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: 14

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
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,223,932
Messages
6,175,468
Members
452,646
Latest member
tudou

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