Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
rvs rvs is offline
external usenet poster
 
Posts: 8
Default Do Until Loop


Hello all,

Here's my problem...

I'm in the process of writing a program that will allow the user to select a
month and week number (1 through 5 for each week of the month) for that
particular month by means of a dialog box. When the user clicks the OK
button, the program finds the appropriate month and the appropriate week
number for that month and colors that cell blue.

I've set the value in the Month combo box equal to a variable and then wrote
a Do Until loop so that the program will stop on the cell whose value is the
same as the month selected in the combo box. That part works fine.

I have another combo box where the user can select the week number for that
particular month. I tried writing another Do Until loop that will tell the
program to stop on the cell whose value is equal to the selected week number,
but it doesn't work. The program keeps looping and doesn't seem to recognize
when the cell value is equal to the week number variable.

My code is below...


Private Sub OKButton_Click()

SelectedMonth = ComboBox1.Value

WeekNum = ComboBox2.Value

'Find month on spreadsheet that matches month selected by user

x = 13
Do Until Cells(2, x).Value = SelectedMonth
x = x + 5
Loop
Cells(2, x).Select

'Find week number underneath correct month that matches week number selected
by user
'Variable 'x' represents the first week of the month selected by user

Do Until Cells(3, x).Value = WeekNum
x = x + 1
Loop


End Sub


Any help would be much appreciated!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Do Until Loop



RVS;394505 Wrote:
Hello all,

Here's my problem...

I'm in the process of writing a program that will allow the user to
select a
month and week number (1 through 5 for each week of the month) for
that
particular month by means of a dialog box. When the user clicks the OK
button, the program finds the appropriate month and the appropriate
week
number for that month and colors that cell blue.

I've set the value in the Month combo box equal to a variable and then
wrote
a Do Until loop so that the program will stop on the cell whose value
is the
same as the month selected in the combo box. That part works fine.

I have another combo box where the user can select the week number for
that
particular month. I tried writing another Do Until loop that will tell
the
program to stop on the cell whose value is equal to the selected week
number,
but it doesn't work. The program keeps looping and doesn't seem to
recognize
when the cell value is equal to the week number variable.

My code is below...


Private Sub OKButton_Click()

SelectedMonth = ComboBox1.Value

WeekNum = ComboBox2.Value

'Find month on spreadsheet that matches month selected by user

x = 13
Do Until Cells(2, x).Value = SelectedMonth
x = x + 5
Loop
Cells(2, x).Select

'Find week number underneath correct month that matches week number
selected
by user
'Variable 'x' represents the first week of the month selected by user

Cells(2, x).Select


End Sub


Any help would be much appreciated!


Hello RVS,

The reason the loop doesn't recognize either the SelectedMonth or
WeekNum is the ComboBox values are always Text. If you type a number
into a cell then the cell value is a number. If you type a date, the
date is stored internally as a number but displayed as text. The fix
here is simple. Don't compare use the cell Value property, but rather
the cell Text property.

x = 13
Do Until Cells(2, x).Text = SelectedMonth
x = x + 5
Loop
Cells(2, x).Select


--
Leith Ross

Sincerely,
Leith Ross

'The Code Cage' (http://www.thecodecage.com/)
------------------------------------------------------------------------
Leith Ross's Profile: http://www.thecodecage.com/forumz/member.php?userid=75
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=110210

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Do Until Loop


You can also use a conversion function.

Do Until Cells(3, x).Value = CInt(WeekNum)
x = x + 1
Loop



"RVS" wrote in message
...
Hello all,

Here's my problem...

I'm in the process of writing a program that will allow the user to select
a
month and week number (1 through 5 for each week of the month) for that
particular month by means of a dialog box. When the user clicks the OK
button, the program finds the appropriate month and the appropriate week
number for that month and colors that cell blue.

I've set the value in the Month combo box equal to a variable and then
wrote
a Do Until loop so that the program will stop on the cell whose value is
the
same as the month selected in the combo box. That part works fine.

I have another combo box where the user can select the week number for
that
particular month. I tried writing another Do Until loop that will tell the
program to stop on the cell whose value is equal to the selected week
number,
but it doesn't work. The program keeps looping and doesn't seem to
recognize
when the cell value is equal to the week number variable.

My code is below...


Private Sub OKButton_Click()

SelectedMonth = ComboBox1.Value

WeekNum = ComboBox2.Value

'Find month on spreadsheet that matches month selected by user

x = 13
Do Until Cells(2, x).Value = SelectedMonth
x = x + 5
Loop
Cells(2, x).Select

'Find week number underneath correct month that matches week number
selected
by user
'Variable 'x' represents the first week of the month selected by user

Do Until Cells(3, x).Value = WeekNum
x = x + 1
Loop


End Sub


Any help would be much appreciated!



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
returning back to loop check condition without completing the loop ashish128 Excel Programming 13 April 3rd 08 12:53 PM
Loop to Filter, Name Sheets. If Blank, Exit Loop ryguy7272 Excel Programming 3 February 5th 08 03:41 PM
Naming Worksheets - Loop within a loop issue klysell Excel Programming 5 March 29th 07 05:48 AM
(Complex) Loop within loop to create worksheets klysell Excel Programming 1 March 20th 07 12:03 AM
Advancing outer Loop Based on criteria of inner loop ExcelMonkey Excel Programming 1 August 15th 05 05:23 PM


All times are GMT +1. The time now is 10:50 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"