发布网友 发布时间:2022-04-22 10:05
共5个回答
热心网友 时间:2023-09-23 09:58
1、alt+F11,插入模块,
2、双击插入的模块,输入下面代码
Public Function MinusString(Str1, Str2, Str3 As String) As String
Dim i, j, k As Integer
Dim aStr As String
i = Len(Str2)
j = Len(Str3)
For k = 1 To i
aStr = Mid(Str2, k, 1)
Str1 = Replace(Str1, aStr, "", 1, 1, vbTextCompare)
Next
For k = 1 To j
aStr = Mid(Str3, k, 1)
Str1 = Replace(Str1, aStr, "", 1, 1, vbTextCompare)
Next
MinusString = Str1
End Function
3、在D2使用公式=MinusString(A1,A2,A3)
热心网友 时间:2023-09-23 09:58
ALT+F11打开VBA编辑窗口,在左边列表栏点击鼠标右键选插入模块,粘贴下面的代码,然后关闭VBA编辑器,
自定义函数的使用方法跟内置函数类似
mnum(源字符串,要减去的字符串1,要减去的字符串2(可选))
例如你举得例子,在D1 输入=mnum(A1,B1,C1)可得到1
Function MNum(Sstr, Dstr1 As String, Optional Dstr2 As String)
Set dic = CreateObject("Scripting.Dictionary")
arr = Array(Dstr1, Dstr2)
For i = 0 To UBound(arr)
For ii = 1 To Len(arr(i))
dic(Mid(arr(i), ii, 1)) = dic(Mid(arr(i), ii, 1)) + 1
Next
Next
For Each d In dic.keys
Sstr = Replace(Sstr, d, "", 1, dic(d))
Next
MNum = Sstr
End Function追问
不好意思 再麻烦你一下
热心网友 时间:2023-09-23 09:59
=A1-B1-C1
热心网友 时间:2023-09-23 09:59
按ALT+F11,插入模块
双击模块,复制下面代码进去粘贴
Function ZbStr(STR1, STR2, STR3, STR4 As String)
Dim M1, M2, M3
M1 = STR1 & STR2
M2 = STR3 & STR4
For M3 = 1 To Len(M2)
M1 = Replace(M1, Mid(M2, M3, 1), "", 1, 1)
Next
ZbStr = M1
End Function
然后在E1输入:
=ZBSTR(A1,B1,C1,D1)
热心网友 时间:2023-09-23 10:00
如果坚持A1-B1-C1=D1的公式不变的话,你的提问不可能实现,因为公式本身就是反映数据运算的,不是减字符的。