如果某些字符,然后添加逗号

我需要一个macros来查找如下所示的字符:“大写”“小写”“大写”

我试过这个:

If character like "[AZ]", "[az]", "[AZ]" then...... 

括号在不同的地方,这是行不通的。

请让我知道我做错了什么

使用公式可以吗?

 =IF ( AND (ISNUMBER(FIND((MID(B4,1,1)),$D$4,1)), ISNUMBER(FIND((MID(B4,2,1)),$D$5,1)), ISNUMBER(FIND((MID(B4,3,1)),$D$4,1)) ), "True", "False") 

其中单元格B4包含您的文本在testing中,例如,“AcK”

  cell D4 contains the string "ABCDEFGHIJKLMNOPQRSTUVWXYZ" cell D5 contains the string "abcdefghijklmnopqrstuvwxyz" 
 ? "AcK" like "[AZ][az][AZ]" '>> True ? "ACK" like "[AZ][az][AZ]" '>> False 

如果我理解了你的目标,试着在你的项目中包含这样的function:

 Public Function editString(ByVal nativeString As String) As String Dim subStr As String, subStr2 As String For j = 1 To Len(nativeString) subStr = Mid(nativeString, j, 3) If subStr Like "[AZ][az][AZ]" Then subStr2 = Left(subStr, 2) & "," & Right(subStr, 1) nativeString = Replace(nativeString, subStr, subStr2) End If Next j editString = nativeString End Function 

然后通过简单地将它们传递给函数来修改string对象:

 Public Sub ModifyString() Dim newString As String: newString = editString("stAcKoverflow") End Sub 

你应该得到你想要的。