Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Creating a List Box on the fly

I have a start date and and an end date as ranges in a
worksheet and would like the user to input a date in
between the start end and dates, with the only allowable
dates being the first of each month. Can I create a list
box that would have the permissible dates and have the
user choose one? Is this doable on the fly, since the
start and end dates frequently change? Would someone have
some sample code?

Thanks in advance

Ray Kanner
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 28
Default Creating a List Box on the fly

Hi Ray

My understanding of your requirements is:

take random start date and present user with a list of 1st of months between
then and the finish date?

Will these dates spread over more than one calendar year? ie could they
have a start date of June 15th 2002 and an end date of August 15th 2003. Or
will they always be within 12 months of each other or? What would the first
available date be if the start date was June 15th - June 1st or July 1st?
and for the end date?

If the start date is in cell A6 and the end date is in cell A7 and you have
a userform called userform1, the following code makes a good stab at it and
you should be able to tweak it as required.


Sub macro1()
Dim startmonth, endmonth As Integer
Dim x As Integer 'counter variable
Dim months(11) As String 'array for month names
Dim rollover As Boolean ' used to loop if start month is later than
endmonth

'fill the array of month names
months(0) = "January"
months(1) = "February"
months(2) = "March"
months(3) = "April"
months(4) = "May"
months(5) = "June"
months(6) = "July"
months(7) = "August"
months(8) = "September"
months(9) = "October"
months(10) = "November"
months(11) = "Decemeber"

'get the start and end months
startmonth = Month(Range("a6"))
endmonth = Month(Range("a7"))

'set rollover as applicable
rollover = (startmonth endmonth)

'pop a box up with the "read in" start and end months
MsgBox ("Start month = " & startmonth & " and end month = " & endmonth)

'empty the list before starting
UserForm1.ListBox1.Clear

'loop through months adding them to the listbox as required
x = startmonth

'x<=endmonth will be final stop case as rollover will definitely be(or
become) false
While ((x <= endmonth) Or (rollover))
'add the current month to the list box
UserForm1.ListBox1.AddItem months(x - 1)

'increment the month we're looking at
x = x + 1

'check to see if we need to begin again in January (ie we've hit
December and
'there's still more to do (rollover would be true)
If ((x 11) And (rollover)) Then
'as there's more to do, set x = 1 to start at
January
x = 1
'and set rollover to false so that we don't loop
forever
rollover = False
End If
Wend

'show the form with the relevant months being available
UserForm1.Show

End Sub


Hope this is of use

David


"Ray Kanner" wrote in message
...
I have a start date and and an end date as ranges in a
worksheet and would like the user to input a date in
between the start end and dates, with the only allowable
dates being the first of each month. Can I create a list
box that would have the permissible dates and have the
user choose one? Is this doable on the fly, since the
start and end dates frequently change? Would someone have
some sample code?

Thanks in advance

Ray Kanner



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
Help Creating a Drop Down List from a List in another worksheet Pat Excel Discussion (Misc queries) 1 November 25th 08 06:44 PM
Creating a Detailed List from a Summary List [email protected] Excel Worksheet Functions 0 September 7th 06 12:36 AM
Creating A Breakout List from a Summary List [email protected] Excel Discussion (Misc queries) 0 September 6th 06 11:58 PM
Creating a List based on your choice from Another List Cristi Excel Discussion (Misc queries) 1 August 14th 06 06:00 PM
Creating a list from an existing list. Jad Excel Worksheet Functions 1 October 29th 04 06:00 AM


All times are GMT +1. The time now is 05:33 PM.

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

About Us

"It's about Microsoft Excel"