Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Date format in a listbox

dim myRng as range
dim myCell as range

with worksheets("somesheetnamehere")
'just the first column
set myrng = .range(strRange).offset(2,0).resize(3,1)
end with

with me.lstnumberanddate
for each mycell in myrng.cells
.additem mycell.value
.List(.ListCount - 1, 1) = format(myCell.Offset(0, 1).Value, "yyyy-mm-dd")
next mycell
end with

(untested, uncompiled. Watch for typos.)

Jac Tremblay wrote:

Hi,
I have read many posts on date formats and many answers from Tom Ogilvy and
others. I learned that if a date in a cell can be interpreted as a US date,
it will. So one can apply a specified format through code like this:
Me.txtDateStart = _
Format(.Range(strRange).Offset(1, 4).Value, "yyyy-mm-dd")
My first problem is now resolved. I have a second one.
I have a two column list of data in the sheet that I load in a list box
through code like this:
Me.lstNumberAndDate.List = _
.Range(strRange).Offset(2, 0).Resize(3, 2).Value
The first column is a number and the second is a date. When I load the data
in the list, the date appears in US format. How can I have it in
international format like the others?
Will I have to split the data in two or load it in two operations? If so,
can someone tell me how?
Thanks.
--
Jac Tremblay


--

Dave Peterson
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Date format in a listbox

Hi Dave,
That is exactly the solution I found in the newsgroup. You were faster to
code it than me.
Tomorrow, i will post the exact solution I will use.
Thank you very much. I appreciate.
Good night.
--
Jac Tremblay


"Dave Peterson" wrote:

dim myRng as range
dim myCell as range

with worksheets("somesheetnamehere")
'just the first column
set myrng = .range(strRange).offset(2,0).resize(3,1)
end with

with me.lstnumberanddate
for each mycell in myrng.cells
.additem mycell.value
.List(.ListCount - 1, 1) = format(myCell.Offset(0, 1).Value, "yyyy-mm-dd")
next mycell
end with

(untested, uncompiled. Watch for typos.)

Jac Tremblay wrote:

Hi,
I have read many posts on date formats and many answers from Tom Ogilvy and
others. I learned that if a date in a cell can be interpreted as a US date,
it will. So one can apply a specified format through code like this:
Me.txtDateStart = _
Format(.Range(strRange).Offset(1, 4).Value, "yyyy-mm-dd")
My first problem is now resolved. I have a second one.
I have a two column list of data in the sheet that I load in a list box
through code like this:
Me.lstNumberAndDate.List = _
.Range(strRange).Offset(2, 0).Resize(3, 2).Value
The first column is a number and the second is a date. When I load the data
in the list, the date appears in US format. How can I have it in
international format like the others?
Will I have to split the data in two or load it in two operations? If so,
can someone tell me how?
Thanks.
--
Jac Tremblay


--

Dave Peterson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 99
Default Date format in a listbox

Hi Dave,
As I said yesterday, here is the code I use:
Dim rngCell As Excel.Range
Dim rng1stCol As Excel.Range
Set rng1stCol = .Range(.Range(strRange).Offset(2, 0), _
.Range(strRange).Offset(2, 0).End(xlDown))
For Each rngCell In rng1stCol
Me.lstNumberAndDate.AddItem rngCell.Value
Me.lstNumberAndDate.List(Me.lstNumberAndDate.ListC ount - 1, 1) = _
Format(rngCell.Offset(0, 1).Value, "yyyy-mm-dd")
Next rngCell
It works in Exce 2000 and 2007.
Thanks again for your precious comment.
--
Jac Tremblay


"Dave Peterson" wrote:

dim myRng as range
dim myCell as range

with worksheets("somesheetnamehere")
'just the first column
set myrng = .range(strRange).offset(2,0).resize(3,1)
end with

with me.lstnumberanddate
for each mycell in myrng.cells
.additem mycell.value
.List(.ListCount - 1, 1) = format(myCell.Offset(0, 1).Value, "yyyy-mm-dd")
next mycell
end with

(untested, uncompiled. Watch for typos.)

Jac Tremblay wrote:

Hi,
I have read many posts on date formats and many answers from Tom Ogilvy and
others. I learned that if a date in a cell can be interpreted as a US date,
it will. So one can apply a specified format through code like this:
Me.txtDateStart = _
Format(.Range(strRange).Offset(1, 4).Value, "yyyy-mm-dd")
My first problem is now resolved. I have a second one.
I have a two column list of data in the sheet that I load in a list box
through code like this:
Me.lstNumberAndDate.List = _
.Range(strRange).Offset(2, 0).Resize(3, 2).Value
The first column is a number and the second is a date. When I load the data
in the list, the date appears in US format. How can I have it in
international format like the others?
Will I have to split the data in two or load it in two operations? If so,
can someone tell me how?
Thanks.
--
Jac Tremblay


--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Format date in Multi-column listbox Sue[_2_] Excel Programming 2 June 16th 08 08:41 AM
Excel Form: Can't format date in a Multi-column Listbox Sue[_2_] Excel Programming 0 June 3rd 08 05:37 AM
Date Format in a Userform Listbox Deke Excel Programming 3 February 21st 07 10:46 PM
Date Format in a Userform Listbox Joel Excel Programming 0 February 21st 07 02:17 PM
Date Format in a Userform Listbox Deke Excel Programming 1 February 21st 07 01:58 PM


All times are GMT +1. The time now is 02:05 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"