Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fill ComboBox with all dates between two ranges.


I have a worksheet with a combo box on it. Each time I execute one of
my macros, I need all the values in the combobox to be cleared out,
then filled with all the dates between two ranges. In my sheet, I have
two cells with two dates. In P3 I have 1/1/1998. In P4 I have
2/1/2006. I need the combobox to list all the months in this range. I
would like to have the formatted as 1998 Jan, 1998 Feb, etc...

The entire combo box would have all the dates from Jan 1, 1998 to
(currently) Feb, 1, 2006.

1998 Jan
1998 Feb
...
...
...
2006 Jan
2006 Feb

Any ideas?? I don't have all my dates listed out, so I'm wondering if
that would be a problem?

TIA,
DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Fill ComboBox with all dates between two ranges.

With Combobox1
.Clear
For i = Range("P3").Value To Range("P4").Value
.AddItem Format(i,"dd mmm yyyy")
Next i
End With

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DejaVu" wrote in
message ...

I have a worksheet with a combo box on it. Each time I execute one of
my macros, I need all the values in the combobox to be cleared out,
then filled with all the dates between two ranges. In my sheet, I have
two cells with two dates. In P3 I have 1/1/1998. In P4 I have
2/1/2006. I need the combobox to list all the months in this range. I
would like to have the formatted as 1998 Jan, 1998 Feb, etc...

The entire combo box would have all the dates from Jan 1, 1998 to
(currently) Feb, 1, 2006.

1998 Jan
1998 Feb
..
..
..
2006 Jan
2006 Feb

Any ideas?? I don't have all my dates listed out, so I'm wondering if
that would be a problem?

TIA,
DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile:

http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fill ComboBox with all dates between two ranges.


Thanks for the response Bob,

I get an error on the *.Clear* line

The only thing I changed in your code was the name of the combobox from
_With_Combobox1_ to _With_cmbDropDownDate_.

Error:
Run-Time error '-2147467259 (80004005)':
Unspecified error.

Thanks,
DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Fill ComboBox with all dates between two ranges.

That shouldn't be a problem. It is a control toolbox or userform combobox I
assume.

Maybe just remove the line. It is only really necessary when re-populating.

--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DejaVu" wrote in
message ...

Thanks for the response Bob,

I get an error on the *.Clear* line

The only thing I changed in your code was the name of the combobox from
_With_Combobox1_ to _With_cmbDropDownDate_.

Error:
Run-Time error '-2147467259 (80004005)':
Unspecified error.

Thanks,
DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile:

http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Fill ComboBox with all dates between two ranges.


Bob - Thanks for your help. That is exactly what I was looking for. I
only had one small problem with it; it added each day within that
range. I was able to easily overcome this with:

Code:
--------------------
tmpDate = DateAdd("yyyy", 1, Sheets(1).Range("P3"))
With Sheets(1).cmbBox1
.Clear
Do Until tmpDate Sheets(1).Range("P4").Value
.AddItem Format(tmpDate, "yyyy mmm")
tmpDate = DateAdd("m", 1, tmpDate)
Loop
End With
--------------------


I have one more question though. If I copy this worksheet to a new
workbook, all the dates in the drop down menu are gone. Is it possible
to have it retain those values?

Thanks again for all your help,

DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile: http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Fill ComboBox with all dates between two ranges.

Not really sure what is causing that, but have you adjusting the combo
reference/

tmpDate = DateAdd("yyyy", 1, Sheets(1).Range("P3"))
With Activesheet.cmbBox1
.Clear
Do Until tmpDate Sheets(1).Range("P4").Value
.AddItem Format(tmpDate, "yyyy mmm")
tmpDate = DateAdd("m", 1, tmpDate)
Loop
End With


--
HTH

Bob Phillips

(remove nothere from email address if mailing direct)

"DejaVu" wrote in
message ...

Bob - Thanks for your help. That is exactly what I was looking for. I
only had one small problem with it; it added each day within that
range. I was able to easily overcome this with:

Code:
--------------------
tmpDate = DateAdd("yyyy", 1, Sheets(1).Range("P3"))
With Sheets(1).cmbBox1
.Clear
Do Until tmpDate Sheets(1).Range("P4").Value
.AddItem Format(tmpDate, "yyyy mmm")
tmpDate = DateAdd("m", 1, tmpDate)
Loop
End With
--------------------


I have one more question though. If I copy this worksheet to a new
workbook, all the dates in the drop down menu are gone. Is it possible
to have it retain those values?

Thanks again for all your help,

DejaVu


--
DejaVu
------------------------------------------------------------------------
DejaVu's Profile:

http://www.excelforum.com/member.php...o&userid=22629
View this thread: http://www.excelforum.com/showthread...hreadid=528631



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
Fill a Combobox from a ROW? Rob[_5_] Excel Discussion (Misc queries) 4 January 15th 09 08:12 PM
fill combobox depending on selection from another combobox Adam Francis Excel Discussion (Misc queries) 2 July 24th 08 07:39 PM
ranges in combobox natanz[_2_] Excel Programming 2 November 21st 05 12:28 PM
Fill combobox from specified range anb001[_5_] Excel Programming 4 June 24th 04 09:41 PM
Fill a combobox karibou Excel Programming 2 January 27th 04 04:13 PM


All times are GMT +1. The time now is 03:23 PM.

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"