Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default If statement not working

Two questions about the following code.
1- why is it not working?
2- is there a cleaner way to accomplish this?

Sub Test()

If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
End If

If Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
If Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\Dave
Sipes\DavProjTimeTracking.xls"
If Range("F4") < "" Then
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
End If
End If

MsgBox (mySourceWkbkName2)

End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default If statement not working


you can give this a try

Sub Test()
Dim mySourceWkbkName2 As String
If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
ElseIf Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
ElseIf Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\DaveSipes\DavProjTimeTracking.xls"
Else
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
MsgBox (mySourceWkbkName2)

End Sub

--


Gary


"Jay" wrote in message
...
Two questions about the following code.
1- why is it not working?
2- is there a cleaner way to accomplish this?

Sub Test()

If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
End If

If Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
If Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\Dave
Sipes\DavProjTimeTracking.xls"
If Range("F4") < "" Then
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
End If
End If

MsgBox (mySourceWkbkName2)

End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default If statement not working

Try this idea. It could even be a worksheet_change event requiring no
action.

Sub selectcasef4()
Select Case UCase(Range("f4"))
Case "DAVE": x = "Dave"
Case "BILL": x = "Bill"
Case Else
MsgBox "No name": Exit Sub
End Select
MsgBox x
End Sub
--
Don Guillett
SalesAid Software

"Jay" wrote in message
...
Two questions about the following code.
1- why is it not working?
2- is there a cleaner way to accomplish this?

Sub Test()

If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
End If

If Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
If Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\Dave
Sipes\DavProjTimeTracking.xls"
If Range("F4") < "" Then
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
End If
End If

MsgBox (mySourceWkbkName2)

End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default If statement not working

Give this a whirl... I was not too sure if you wanted to open the books or
not... I made guess...

Sub Test()
dim mySourceWkbkName2 as workbook

Select Case Range("F4").Value
Case ""
MsgBox "Enter Person Reporting in Cell F4"
Case "Jay"
Set mySourceWkbkName2 =
Workbooks.Open("F:\files\ProjTimeTracking.xls")
Case "Dave"
Set mySourceWkbkName2 =
Workbooks.Open("H:\FAC\DaveSipes\DavProjTimeTracki ng.xls")
Case Else
MsgBox "Person Reporting name mispelled"
End Select

MsgBox (mySourceWkbkName2.Name)

End Sub
--
HTH...

Jim Thomlinson


"Jay" wrote:

Two questions about the following code.
1- why is it not working?
2- is there a cleaner way to accomplish this?

Sub Test()

If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
End If

If Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
If Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\Dave
Sipes\DavProjTimeTracking.xls"
If Range("F4") < "" Then
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
End If
End If

MsgBox (mySourceWkbkName2)

End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
Jay Jay is offline
external usenet poster
 
Posts: 671
Default If statement not working

Thanks for all the feedback. It looks like any of these ideas will work well.
Thanks for the help!

"Don Guillett" wrote:

Try this idea. It could even be a worksheet_change event requiring no
action.

Sub selectcasef4()
Select Case UCase(Range("f4"))
Case "DAVE": x = "Dave"
Case "BILL": x = "Bill"
Case Else
MsgBox "No name": Exit Sub
End Select
MsgBox x
End Sub
--
Don Guillett
SalesAid Software

"Jay" wrote in message
...
Two questions about the following code.
1- why is it not working?
2- is there a cleaner way to accomplish this?

Sub Test()

If Range("F4") = "" Then
MsgBox "Enter Person Reporting in Cell F4"
Exit Sub
End If

If Range("F4") = "Jay" Then
mySourceWkbkName2 = "F:\files\ProjTimeTracking.xls"
If Range("F4") = "Dave" Then
mySourceWkbkName2 = "H:\FAC\Dave
Sipes\DavProjTimeTracking.xls"
If Range("F4") < "" Then
MsgBox "Person Reporting name mispelled"
Exit Sub
End If
End If
End If

MsgBox (mySourceWkbkName2)

End Sub






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
IF Statement not working Barrett M Excel Worksheet Functions 8 May 6th 08 03:29 PM
If statement working only once Lime Excel Worksheet Functions 0 May 5th 08 03:58 AM
IF statement not working TJAC Excel Discussion (Misc queries) 2 January 13th 06 01:08 PM
For Each Statement still not working Jacqui Excel Programming 6 November 2nd 05 04:01 PM
If statement not working right TimT Excel Programming 2 July 11th 05 06:18 PM


All times are GMT +1. The time now is 11:59 AM.

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"