need help with copying date from userform and changing the format of it before its copied to sheet

kbishop94

Active Member
Joined
Dec 5, 2016
Messages
476
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
I have a macro that runs when the workbook is opened and looks at the date column and takes the date, copies it and pastes it as text in a hidden column so that it reads "Apr-2018" (or whatever the month/year is in the date.)
But I cannot get the same function to work when attempting to do it a command button is hit to copy the data over to the spreadsheet from the form.

Here is what I have so far:

Code:
Private Sub cmdAdd_Click()
Dim ws As Worksheet

[COLOR=#008000]'copy the data entered from the userform to the spreadsheet:[/COLOR]
With ws
 
.Cells(llRow, 2).Value = Me.DTPicker1.Value                                                               [COLOR=#008000]'this is copying the date from my datepicker to the date column (which is visible)[/COLOR]                       
.Cells(llRow, 5).Value = Me.DTPicker1(FormulaR1C1 = "=TEXT(RC[-1],""mmm-yyy"")") [COLOR=#008000]'this is what is not working. I need to take the same date from the datepicker and change it to the format "Apr-2018" and copy it to a hidden column which is column E (5) 
[/COLOR]

I know that this part: Me.DTPicker1(FormulaR1C1 = "=TEXT(RC[-1],""mmm-yyy"")") is not formatted correctly, but no matter how I try to 'arrange it' I still keep getting an error.
 

Excel Facts

Fastest way to copy a worksheet?
Hold down the Ctrl key while dragging tab for Sheet1 to the right. Excel will make a copy of the worksheet.
Try this.
Code:
.Cells(llRow, 5).Value = Format(Me.DTPicker1.Value,"mmm-yyy")
 
Upvote 0
Try this.
Code:
.Cells(llRow, 5).Value = Format(Me.DTPicker1.Value,"mmm-yyy")

Thank you, Norie.
icon14.png
 
Upvote 0
Try this.
Code:
.Cells(llRow, 5).Value = Format(Me.DTPicker1.Value,"mmm-yyy")


Just now had a chance to try this and it doesnt quite give me the return that i need...

It converts the date to: "Jul-18183" instead of "Jul-2018" ???

I tried several different methods, and still cant get it to give me the return I need.

What I am trying to replicate is the return I get if I was using a formula on the spreadheet. This formula gives me the correct return: =TEXT(B413, "mmm-yyyy") I cant get the VBA equivalent to do quite the same. (?)
 
Upvote 0
This is the equivalent of =TEXT(B413, "mmm-yyyy").

Code:
Format(Me.DTPicker1.Value,"mmm-yyy")
 
Upvote 0

Forum statistics

Threads
1,223,958
Messages
6,175,638
Members
452,663
Latest member
MEMEH

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