Combination Date and Funtion

Gowodka

New Member
Joined
Aug 24, 2011
Messages
20
Hi,

So i have 10 buttons on my userform and if i press them i need to find some data according to the button pressed. All the 10 buttons have 1 thing in common they all need the Date, Yearnumber, Montnumber and weeknumber

I could copy the code below 10 times but i wan't to make some sort of Function or subprocedure so whatever button i press it always calculate the date, yearNumber, MonthNumber and the weeknumber

I just don't understand how to do this, i'm quite new to this

Code:
    Public Datum As Date           'the current Date
    Public DatumMaand As Single    'number of the Month
    Public DatumWeek As Single     'number of the week
    Public DatumJaar As Single     'Number of the Year
    
    Datum = Date
    DatumMaand = Month(Datum)
    DatumWeek = DatePart("ww", Datum, vbMonday, vbFirstFourDays)
    DatumJaar = DatePart("YYYY", Datum, vbMonday, vbFirstFourDays)


Thanks in advance
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
Someone else then ?

But normally

if i put my global variables in a module for example the Date ( now ) and weeknumber

Code:
Public Datum As Date
Public Month

and i make a function that is also in the same module

Code:
Function GiveDateInfo()
     Datum = Date
     Month= Month(Datum)
End Function

And then in my userform i use
Code:
Call GiveDateInfo
Range("A1") = Datum
Range("A2") = Month
That just everything.
This should work right ?
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

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