LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting "r" to = range selected in an IF statement?


Hi all, i am having trouble setting "r" to be the range selected during
the first IF statement, i am trying to get the code to select a
worksheet as defined on a userform (works ok!), then on the worksheet
select a range of times depending on the day selected, then i want it
to select the time found in Userform2.listbox1 and check the offsets
for entries if the offsets contain a value then msgbox blah blah....
the code below works so far but i'm seeing double trying to make it
work properly....Can anyone help?

Regards,
Simon

Public Sub FindSlot()
Dim strFirst As Integer
Dim rng As Range
Dim t1 As Variant
Dim w, vf, t
Dim r As Range
Dim mycell
Application.EnableEvents = False
w = UserForm2.ComboBox3.Value
vf = UserForm2.ListBox1.Value
Worksheets(w).Visible = True
Worksheets(w).Select
t = UserForm2.ComboBox1.Value
If t = "Tuesday" Then
Worksheets(w).Range("A4:A46").Select
ElseIf t = "Wednesday" Then
Worksheets(w).Range("A49:A94").Select
ElseIf t = "Thursday" Then
Worksheets(w).Range("A97:A142").Select
ElseIf t = "Friday" Then
Worksheets(w).Range("A145:A190").Select
ElseIf t = "Saturday" Then
Worksheets(w).Range("A193:A238").Select
End If
'NEED TO KNOW HOW TO SET r AS RANGE HERE!
On Error GoTo XIT
Application.EnableEvents = False

For Each mycell In r
If mycell.Value = vf.Value Then
mycell.Select
If mycell.Offset(0, 1) < "" Or mycell.Offset(0, 3) < "" Or
mycell.Offset(0, 5) < "" Or mycell.Offset(0, 7) < "" Or
mycell.Offset(0, 9) < "" Or mycell.Offset(0, 11) < "" Then
If MsgBox("Please Choose New Time, Day or Week... " & mycell.Value & "
Is Taken!", _
vbOKOnly, "Time Slot Taken") = vbOK Then
Exit Sub
ElseIf mycell.Offset(0, 1) = "" Or mycell.Offset(0, 3) = "" Or
mycell.Offset(0, 5) = "" Or mycell.Offset(0, 7) = "" Or
mycell.Offset(0, 9) = "" Or mycell.Offset(0, 11) = "" Then
If MsgBox("Click Yes to Make Booking or Click No To Exit", vbYesNo,
"Make A Booking?") = vbYes Then
Unload UserForm2
UserForm1.Show
End If
End If
End If
End If
Next
Worksheets(w).Visible = False
XIT:
Application.EnableEvents = True
Unload UserForm2
End Sub


--
Simon Lloyd
------------------------------------------------------------------------
Simon Lloyd's Profile: http://www.excelforum.com/member.php...fo&userid=6708
View this thread: http://www.excelforum.com/showthread...hreadid=557563

 
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 with setting a "not found" statement Pierre Excel Discussion (Misc queries) 2 April 21st 10 02:53 AM
Help with setting a "nof found" statement Pierre Excel Discussion (Misc queries) 1 April 20th 10 11:37 PM
Hide all "except" the visible selected range(s)? Spiky Excel Worksheet Functions 2 August 4th 08 09:56 PM
Hide all "except" the visible selected range(s)? Pierre Excel Worksheet Functions 0 August 2nd 08 07:17 PM
use variable in Workbooks("book1").Worksheets("sheet1").Range("a1" Luc[_3_] Excel Programming 2 September 28th 05 08:37 PM


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