-
-
chenz 数据达人Lv4
发表于2020-12-8 15:44
悬赏50
已解决
楼主
如题
最佳答案
chenz 发表于 2020-12-8 17:12
不行吧 我这是固定报表 不是浮动的 加了$肯定不行啊
好吧 那表格中去掉vb函数试试吧,感觉是这个函数的问题
16个回答
xxxl 发表于 2020-12-8 16:37
没太明白 vb函数,excel里的有关宏的数据 以及excel导入规则可以看一下吗
VB函数:Option Explicit
Sub Worksheet_Change(ByVal Target As Range)
'让数据有效性选择 可以多选,重复选
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If oldVal = "" Then
Else
If newVal = "" Then
Else
Dim oldValArray
oldValArray = Split(oldVal, ",")
Dim exitVal As Boolean
exitVal = False
Dim i As Integer
Dim resultVal As String
For i = 0 To UBound(oldValArray)
If oldValArray(i) = newVal Then
exitVal = True
Else
If resultVal = "" Then
resultVal = oldValArray(i)
Else
resultVal = resultVal & "," & oldValArray(i)
End If
End If
Next
If exitVal = False Then
If oldVal = newVal Then
Target.Value = resultVal
Else
Target.Value = resultVal & "," & newVal
End If
Else
Target.Value = resultVal
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub

chenz 发表于 2020-12-8 16:54
VB函数:Option Explicit
Sub Worksheet_Change(ByVal Target As Range)
导入规则格式改成这种试试 加$符号
