View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Ted M H Ted M H is offline
external usenet poster
 
Posts: 83
Default Check if variable contains a string

I'm trying to write VBA code that will look at a String variable and tell me
whether or not that String contains another String €” without erroring out.
Variable X contains this string: =SUM(AAAA,BBBB)
Variable Y contains this string: PPPP
I want something that works sort of like this:
If Variable X contains Variable Y, Then Variable W = 1
If Variable X does not contain Variable Y, Then Variable W = 2
In the example above, W will equal 2, since X does not contain Y
If Y is BBBB then W will equal 1, because X does contain Y
Many thanks.