Problem with formatting

Hashiru

Active Member
Joined
May 29, 2011
Messages
286
Can any one help please.
I am having problem formating my code. I want the code to format each additional cell by clearing any format in that cell and place the desired form.

Desired format: 01/01/2011 "dd/mm/yyyy"

My code:

With Worksheets("Bank Payment").Cells(7, 1).Resize(nextrow, 1)
.Clear
.NumberFormat = "dd/MM/yyyy"
End With

nextrow is a variable that change each time an entry is made


I want to type 01/01/11 and the code format it to 01/01/2011

thanks
 
Last edited:

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Can I ask why you don't format your input area beforehand?

Also, if you want to do this with VBA have you considered using the sheet event Worksheet_Change to alter the format of entered cells?
 
Upvote 0
Thanks for your reply
My intention was to clear any previous format on the cell where the date is to be input and then input the date and lastly format it.
Column A is where I intend the date to be input starting from row 7. I am avoiding clearing the whole column because the user might want to do some calculations at the buttom.
I am actually designing a form to input data into excel worksheet and this code suppose to be behind the ok buttom specifically on the date textbox called datetext.
Thanks for your reply once more.
 
Upvote 0
If you know which cell you are putting the data into, then why can't you format that cell straight after putting the data into it?
 
Upvote 0
this is how far I have gone. thanks

Private Sub OKButton_Click()
'Find the next row of the data sheet
nextrow = Worksheets("Bank Payment").Cells(Rows.Count, 1).End(xlUp).Row + 1
'Transfer data from ExpenseClassificationForm to worksheet
With Worksheets("Bank Payment")
.Cells(nextrow, 1).ClearFormats
.Cells(nextrow, 1).Value = Me.DateText
.Cells(nextrow, 1).NumberFormat = vbShortDate
End With
 
Upvote 0
Hi
Thanks
Private Sub OKButton_Click()
'Find the next row of the data sheet
nextrow = Worksheets("Bank Payment").Cells(Rows.Count, 1).End(xlUp).Row + 1
'Transfer data from ExpenseClassificationForm to worksheet
With Worksheets("Bank Payment")
.Cells(nextrow, 1).ClearFormats
.Cells(nextrow, 1).Value = Me.DateText
.Cells(nextrow, 1).NumberFormat = vbShortDate
End With

The macro recorder is giving me short date code as "d/m/yyyy" if replaced with the vbShortDate constant it give exactly the same result.
A green triangle on the cell where the date is input says
Text Date with 2-digit year
convert xx to 19xx
convert xx to 20xx
my system date is set to convert 2 digit year between 1930 and 2029.
Thanks

N/B: Can you show me how to insert screen shot on this message board. This is for you to see what's going on.
 
Upvote 0
What are the contents of me.DateText? Have you considered converting whatever that is to a dateserial number for input to the cell?
 
Upvote 0
Thanks

Me.DateText transfer the value in textbox to excel in the designated cell.

If I know how to show you a screen shot I shall show you exaclty what I am saying

Thanks
 
Upvote 0
Change this:
Code:
.Cells(nextrow, 1).Value = Me.DateText
to
Code:
.Cells(nextrow, 1).Value = CDate(Me.DateText)
 
Upvote 0
hi thanks for your help

I think I have came up with a solution. I guess you may want to take a look at it. See below:

Private Sub OKButton_Click()
'Find the next row of the data sheet
nextrow = Worksheets("Bank Payment").Cells(Rows.Count, 1).End(xlUp).Row + 1
'Transfer data from ExpenseClassificationForm to worksheet
With Worksheets("Bank Payment")
.Cells(nextrow, 1).ClearFormats
.Cells(nextrow, 1).Value = Me.DateText
.Cells(nextrow, 1) = Format((Me.DateText), "dd/mm/yyyy")

End With
Thanks once more for your contributions to this solution.
 
Upvote 0

Forum statistics

Threads
1,224,594
Messages
6,179,792
Members
452,942
Latest member
VijayNewtoExcel

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