Does the cell contain...

  • Thread starter Thread starter Raulito
  • Start date Start date
R

Raulito

Hi,

I'm trying to do the following:
if the cell G2 contains the value "april" then cell M2 equals April2,
knowing that the cell G2 can contains the value "april" at the beginning or
at the end or anywhere else.
 
Hi Raulito,

One solution is as follows:-

Step 1

Create a fuction as follows:-

Public Function CellG2(txtCellG2 As Variant) As Variant

Dim numIntPos As Long
Dim txtTemp As Variant

CellG2 = "" 'set as default
txtTemp = LCase(txtCellG2) ' make sure everything is
lower case

If Len(txtTemp) < 1 Then Exit Function 'exit if nothing is
contained in CellG2


numIntPos = InStr(1, txtTemp, "april")
If numIntPos > 0 Then CellG2 = "April"
End Function

Step 2

Make Formula for M2 as follows:-

=CellG2(G2)


Step 3

Change the contents of Cell G2 and watch it work

Regards
 
Back
Top