ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Text is contained (https://www.excelbanter.com/excel-programming/394571-text-contained.html)

Mike H.

Text is contained
 
I want to open a text file and read the file one line at a time. If the line
contains certain text, I want to branch and do something different. I
thought this would work:

If vbLine Like "pork" Then

but if the vbLine is "dog,cat,pork" it fails. How do I evaluate for a
portion of the vbLine variable? Other software I've used has a contains
operator:
vbLine!"pork" would mean does the vbLine contain "pork"
vbLine!!"pork" would mean does the vbLine variable NOT contain "pork"
Is there such a think in VBA?

Jim Jackson

Text is contained
 
You might try:
If Instr(1,vbLine,"Pork") Then
--
Best wishes,

Jim


"Mike H." wrote:

I want to open a text file and read the file one line at a time. If the line
contains certain text, I want to branch and do something different. I
thought this would work:

If vbLine Like "pork" Then

but if the vbLine is "dog,cat,pork" it fails. How do I evaluate for a
portion of the vbLine variable? Other software I've used has a contains
operator:
vbLine!"pork" would mean does the vbLine contain "pork"
vbLine!!"pork" would mean does the vbLine variable NOT contain "pork"
Is there such a think in VBA?


Ron Rosenfeld

Text is contained
 
On Wed, 1 Aug 2007 10:32:02 -0700, Mike H.
wrote:

I want to open a text file and read the file one line at a time. If the line
contains certain text, I want to branch and do something different. I
thought this would work:

If vbLine Like "pork" Then

but if the vbLine is "dog,cat,pork" it fails. How do I evaluate for a
portion of the vbLine variable? Other software I've used has a contains
operator:
vbLine!"pork" would mean does the vbLine contain "pork"
vbLine!!"pork" would mean does the vbLine variable NOT contain "pork"
Is there such a think in VBA?


In vba you could use the Instr function
--ron


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com