简体   繁体   中英

Excel FORMULA: Find if all the characters in a cell are in another cell even if in this another cell they are more characters

EXCEL FORMULA: Find if all the characters in a cell are in another cell even if in this another cell they are more characters. Example: A1 contains TRSA - B1 contains JHTHASUBR so return TRUE: all characters in A1 are in B1 even if they are not in order or B1 had more characters.

I don't know if I can do that with a formula in excel? Thank you.

Try the following U ser D efined F unction:

Public Function IsItInThere(r1 As Range, r2 As Range) As Boolean
   Dim v1 As String, v2 As String, CH As String
   Dim i As Long

   IsItInThere = False
   v1 = r1.Text
   v2 = r2.Text

   For i = 1 To Len(v1)
      CH = Mid(v1, i, 1)
      If InStr(v2, CH) = 0 Then
         Exit Function
      End If
   Next i
   IsItInThere = True
End Function

在此处输入图片说明

User Defined Functions (UDFs) are very easy to install and use:

  1. ALT-F11 brings up the VBE window
  2. ALT-I ALT-M opens a fresh module
  3. paste the stuff in and close the VBE window

If you save the workbook, the UDF will be saved with it. If you are using a version of Excel later then 2003, you must save the file as .xlsm rather than .xlsx

To remove the UDF:

  1. bring up the VBE window as above
  2. clear the code out
  3. close the VBE window

To use the UDF from Excel:

=IsItInThere(A1,B1)

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

and

http://msdn.microsoft.com/en-us/library/ee814735(v=office.14).aspx

and for specifics on UDFs, see:

http://www.cpearson.com/excel/WritingFunctionsInVBA.aspx

Macros must be enabled for this to work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM