Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default If Then Else

I am trying to figure out how to set my macro to check a certain variable and
if it meets a specific variable to skip the rest of the macro and end.

If 'variable = X
Then 'skip to the end of the macro and end
Else 'continue on with the rest of the macro

I also am having trouble with some code I was given earlier.

Dim sh As Worksheet
Dim sStr As String

Set sh = ActiveSheet

sStr = "\\HCI\HCI Share\C of A's - Building 4\00-RMHTest-6
ParametersXXXX\"

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

I was told this code would check if the value in B7 was the same as the file
name saved in the location "\\HCI\HCI Share\C of A's - Building
4\00-RMHTest-6
ParametersXXXX\" and if there was a file named the same as the value of B7
that I would get a message "File Exists" but if there was no file with the
name as the value in B7 then it would tell me that "File Does Not Exist".

The code above no matter what value I have in B7 it tells me "File Does Not
Exist" even if i use a value in B7 that already has a file saved as the value
in the location given.

Any help would be appreciated.
Thank you
Ryan Hess

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Then Else

could it be a problem like:

? dir("C:\data6\99budget.xls")
99budget.xls
? dir("C:\data6\99budget")

The second one returns nothing because it is missing the ".xls" on the end.

If x = 10 then Exit sub

--
Regards,
Tom Ogilvy



"ryanmhess" wrote in message
...
I am trying to figure out how to set my macro to check a certain variable

and
if it meets a specific variable to skip the rest of the macro and end.

If 'variable = X
Then 'skip to the end of the macro and end
Else 'continue on with the rest of the macro

I also am having trouble with some code I was given earlier.

Dim sh As Worksheet
Dim sStr As String

Set sh = ActiveSheet

sStr = "\\HCI\HCI Share\C of A's - Building 4\00-RMHTest-6
ParametersXXXX\"

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

I was told this code would check if the value in B7 was the same as the

file
name saved in the location "\\HCI\HCI Share\C of A's - Building
4\00-RMHTest-6
ParametersXXXX\" and if there was a file named the same as the value of B7
that I would get a message "File Exists" but if there was no file with the
name as the value in B7 then it would tell me that "File Does Not Exist".

The code above no matter what value I have in B7 it tells me "File Does

Not
Exist" even if i use a value in B7 that already has a file saved as the

value
in the location given.

Any help would be appreciated.
Thank you
Ryan Hess



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default If Then Else

That may be the problem Tom however I am not sure how to include the ".xls"
with

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

to get it to work.

btw, Thanks for the Exit Sub part, was exactly what I was looking for.
Ryan Hess

"Tom Ogilvy" wrote:

could it be a problem like:

? dir("C:\data6\99budget.xls")
99budget.xls
? dir("C:\data6\99budget")

The second one returns nothing because it is missing the ".xls" on the end.

If x = 10 then Exit sub

--
Regards,
Tom Ogilvy



"ryanmhess" wrote in message
...
I am trying to figure out how to set my macro to check a certain variable

and
if it meets a specific variable to skip the rest of the macro and end.

If 'variable = X
Then 'skip to the end of the macro and end
Else 'continue on with the rest of the macro

I also am having trouble with some code I was given earlier.

Dim sh As Worksheet
Dim sStr As String

Set sh = ActiveSheet

sStr = "\\HCI\HCI Share\C of A's - Building 4\00-RMHTest-6
ParametersXXXX\"

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

I was told this code would check if the value in B7 was the same as the

file
name saved in the location "\\HCI\HCI Share\C of A's - Building
4\00-RMHTest-6
ParametersXXXX\" and if there was a file named the same as the value of B7
that I would get a message "File Exists" but if there was no file with the
name as the value in B7 then it would tell me that "File Does Not Exist".

The code above no matter what value I have in B7 it tells me "File Does

Not
Exist" even if i use a value in B7 that already has a file saved as the

value
in the location given.

Any help would be appreciated.
Thank you
Ryan Hess




  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default If Then Else

If Dir(sStr & sh.Range("B7").Value & ".xls") < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

--
Regards,
Tom Ogilvy

"ryanmhess" wrote in message
...
That may be the problem Tom however I am not sure how to include the

".xls"
with

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

to get it to work.

btw, Thanks for the Exit Sub part, was exactly what I was looking for.
Ryan Hess

"Tom Ogilvy" wrote:

could it be a problem like:

? dir("C:\data6\99budget.xls")
99budget.xls
? dir("C:\data6\99budget")

The second one returns nothing because it is missing the ".xls" on the

end.

If x = 10 then Exit sub

--
Regards,
Tom Ogilvy



"ryanmhess" wrote in message
...
I am trying to figure out how to set my macro to check a certain

variable
and
if it meets a specific variable to skip the rest of the macro and end.

If 'variable = X
Then 'skip to the end of the macro and end
Else 'continue on with the rest of the macro

I also am having trouble with some code I was given earlier.

Dim sh As Worksheet
Dim sStr As String

Set sh = ActiveSheet

sStr = "\\HCI\HCI Share\C of A's - Building 4\00-RMHTest-6
ParametersXXXX\"

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

I was told this code would check if the value in B7 was the same as

the
file
name saved in the location "\\HCI\HCI Share\C of A's - Building
4\00-RMHTest-6
ParametersXXXX\" and if there was a file named the same as the value

of B7
that I would get a message "File Exists" but if there was no file with

the
name as the value in B7 then it would tell me that "File Does Not

Exist".

The code above no matter what value I have in B7 it tells me "File

Does
Not
Exist" even if i use a value in B7 that already has a file saved as

the
value
in the location given.

Any help would be appreciated.
Thank you
Ryan Hess






  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default If Then Else

Thank you very much Tom!

Ryan Hess

"Tom Ogilvy" wrote:

If Dir(sStr & sh.Range("B7").Value & ".xls") < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

--
Regards,
Tom Ogilvy

"ryanmhess" wrote in message
...
That may be the problem Tom however I am not sure how to include the

".xls"
with

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

to get it to work.

btw, Thanks for the Exit Sub part, was exactly what I was looking for.
Ryan Hess

"Tom Ogilvy" wrote:

could it be a problem like:

? dir("C:\data6\99budget.xls")
99budget.xls
? dir("C:\data6\99budget")

The second one returns nothing because it is missing the ".xls" on the

end.

If x = 10 then Exit sub

--
Regards,
Tom Ogilvy



"ryanmhess" wrote in message
...
I am trying to figure out how to set my macro to check a certain

variable
and
if it meets a specific variable to skip the rest of the macro and end.

If 'variable = X
Then 'skip to the end of the macro and end
Else 'continue on with the rest of the macro

I also am having trouble with some code I was given earlier.

Dim sh As Worksheet
Dim sStr As String

Set sh = ActiveSheet

sStr = "\\HCI\HCI Share\C of A's - Building 4\00-RMHTest-6
ParametersXXXX\"

If Dir(sStr & sh.Range("B7").Value) < "" Then
MsgBox "File Exists"
Else
MsgBox "File Does Not Exist"
End If

I was told this code would check if the value in B7 was the same as

the
file
name saved in the location "\\HCI\HCI Share\C of A's - Building
4\00-RMHTest-6
ParametersXXXX\" and if there was a file named the same as the value

of B7
that I would get a message "File Exists" but if there was no file with

the
name as the value in B7 then it would tell me that "File Does Not

Exist".

The code above no matter what value I have in B7 it tells me "File

Does
Not
Exist" even if i use a value in B7 that already has a file saved as

the
value
in the location given.

Any help would be appreciated.
Thank you
Ryan Hess









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



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