Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default usings contains in var check

How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default usings contains in var check

Hi Bruce,

Try something like:

Sub Test01()
Dim myVar As String

' myVar = "myfile01203"

If Len(myVar) 0 Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If
End Sub

---
Regards,
Norman



"Bruce" wrote in message
...
How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default usings contains in var check

Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...

"Norman Jones" wrote:

Hi Bruce,

Try something like:

Sub Test01()
Dim myVar As String

' myVar = "myfile01203"

If Len(myVar) 0 Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If
End Sub

---
Regards,
Norman



"Bruce" wrote in message
...
How do I check that a variable 'contains' something?

eg.

myVar = "myfile01203"

If myVar contains "myfile" then
'do something
End if





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default usings contains in var check

Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default usings contains in var check

Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...


No, you still dont see what he is saying.

sStr= "My dogs name is spot"

if sStr contains "spot" then
' do this code
end if

I havnt any idea how to do this in vba
in c its simple if(strstr(sStr, "spot"))
{
// do code here
}
I too was looking for this but unfortunately MS doesnt list functions in the
help - you have to already know the function name to find it.
At least thats my experience.
Eric



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 138
Default usings contains in var check

Eric,

Ive got it;

If myVar like sStr & "*" Then

Bruce

"Eric" wrote:

Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...


No, you still dont see what he is saying.

sStr= "My dogs name is spot"

if sStr contains "spot" then
' do this code
end if

I havnt any idea how to do this in vba
in c its simple if(strstr(sStr, "spot"))
{
// do code here
}
I too was looking for this but unfortunately MS doesnt list functions in the
help - you have to already know the function name to find it.
At least thats my experience.
Eric


  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default usings contains in var check

Hi Eric,

I think you have the correct interpretation!

Sub Test01()
Dim myVar As String
Dim sStr As String

myVar = "myfile01203"
sStr = "myfile"
myVar = "myfile01203"
If InStr(1, myVar, sStr, vbTextCompare) Then
'do something, e.g.
MsgBox "myVar contains the substring " & sStr
Else
MsgBox sStr & " not found"
End If
End Sub
---
Regards,
Norman



"Eric" wrote in message
news:jzvvd.755094$8_6.482955@attbi_s04...
Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...


No, you still dont see what he is saying.

sStr= "My dogs name is spot"

if sStr contains "spot" then
' do this code
end if

I havnt any idea how to do this in vba
in c its simple if(strstr(sStr, "spot"))
{
// do code here
}
I too was looking for this but unfortunately MS doesnt list functions in
the
help - you have to already know the function name to find it.
At least thats my experience.
Eric



  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default usings contains in var check

so, if
myVar="spot"
sStr= "My dogs name is spot"

then
If myVar like sStr & "*" Then
' code will be executed here for sure?
end if

I dont get the & "*" thing, whats that mean?
Eric


Bruce wrote:

Eric,

Ive got it;

If myVar like sStr & "*" Then

Bruce

"Eric" wrote:

Norman Jones wrote:

Hi Bruce,

sStr = "myfile01203"

If myVar = sStr Then
'do something, e.g.
MsgBox myVar
Else
'do something else?
End If

---
Regards,
Norman



"Bruce" wrote in message
...
Not quite what I was thinking. Let me try again.

I want to test whether my Var contains myfile. Any ideas...


No, you still dont see what he is saying.

sStr= "My dogs name is spot"

if sStr contains "spot" then
' do this code
end if

I havnt any idea how to do this in vba
in c its simple if(strstr(sStr, "spot"))
{
// do code here
}
I too was looking for this but unfortunately MS doesnt list functions in
the
help - you have to already know the function name to find it.
At least thats my experience.
Eric



  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default usings contains in var check

Norman Jones wrote:

Hi Eric,

I think you have the correct interpretation!

Sub Test01()
Dim myVar As String
Dim sStr As String

myVar = "myfile01203"
sStr = "myfile"
myVar = "myfile01203"
If InStr(1, myVar, sStr, vbTextCompare) Then
'do something, e.g.
MsgBox "myVar contains the substring " & sStr
Else
MsgBox sStr & " not found"
End If
End Sub
---
Regards,
Norman

Is that case sensitive? if so how do you ignore case?
if not how do you make it case specific?
Thanks
Eric

  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default usings contains in var check

Hi Eric,

Is that case sensitive?


No.

if not how do you make it case specific?


If InStr(1, myVar, sStr, vbBinaryCompare) Then

---
Regards,
Norman



"Eric" wrote in message
news:w%vvd.190497$V41.190304@attbi_s52...


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
Increase size of a Forms Check Box (click on to enter check mark) 718Satoshi Excel Discussion (Misc queries) 0 August 17th 07 01:52 AM
Usings Text fields in a Pivot Table [email protected] Excel Discussion (Misc queries) 1 August 14th 07 04:18 PM
Check if Conditional Format is True or False / Check cell Color Kevin McCartney Excel Worksheet Functions 5 June 29th 07 11:12 AM
Enable check box in protected sheet + group check boxes Dexxterr Excel Discussion (Misc queries) 4 August 2nd 06 12:00 PM
how can I perform trig. functions usings grads 400deg per circle davystuff Excel Worksheet Functions 2 March 30th 06 03:00 PM


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