Return Year only from MonthView Calendar

Challis

New Member
Joined
Oct 22, 2017
Messages
21
How do i return the year only in a cell from a monthview calendar in a userform.
Currently using the current code, where icnt refers to the last row in the sheet plus 1 and the values are yielded from a userform
"
With Sheets("Register")
.Cells(iCNT, 1) = Calendar.Value
.Cells(iCNT, 2) = iCNT - 99
.Cells(iCNT, 3) = frmData.txtWO
.Cells(iCNT, 4) = cmbREV.Value
.Cells(iCNT, 5) = cmbAREA.Value
.Cells(iCNT, 6) = cmbUNIT.Value
.Cells(iCNT, 7) = frmData.txtEQUIPMENT
.Cells(iCNT, 8) = cmbTYPE1.Value
.Cells(iCNT, 9) = cmbTYPE2.Value
"
For cell (icnt,1), i want a code that returns the year as selected in the monthview calendar. Not the entire date in DD/MM/YY format. Also, if i wanted to return the date in a different format, ie YYMMDD how would i write this code?
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
If Calendar.Value returns a date, then

Code:
.Cells(iCNT, 1).Value = Year(Calendar.Value)

or (faster),

Code:
  With Sheets("Register")
    .Rows(ICNT).Resize(, 9).Value = _
    Array(Year(Calendar.Value), ICNT - 99, frmData.txtWO, cmbREV.Value, _
          cmbAREA.Value, cmbUNIT.Value, frmData.txtEQUIPMENT, cmbTYPE1.Value, cmbTYPE2.Value)
  End With
 
Upvote 0

Forum statistics

Threads
1,215,510
Messages
6,125,241
Members
449,217
Latest member
Trystel

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