Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在excel中删除以逗号分隔的单元格中保存的值_Excel_Csv_Dropdown_Vba - Fatal编程技术网

在excel中删除以逗号分隔的单元格中保存的值

在excel中删除以逗号分隔的单元格中保存的值,excel,csv,dropdown,vba,Excel,Csv,Dropdown,Vba,我有一个元数据表,我在其中设置一些参数,从中生成数据透视。我通过下拉列表选择这些参数 我以逗号分隔的方式将下拉列表的值保存在相应的单元格中。为此,我在该表上有一个宏: Private Sub Worksheet_Change(ByVal Target As Range) 'Set automatic formula calculation ON Application.Calculation = xlAutomatic Dim Oldvalue As String Dim Newvalu

我有一个元数据表,我在其中设置一些参数,从中生成数据透视。我通过下拉列表选择这些参数

我以逗号分隔的方式将下拉列表的值保存在相应的单元格中。为此,我在该表上有一个宏:

 Private Sub Worksheet_Change(ByVal Target As Range)

'Set automatic formula calculation ON
Application.Calculation = xlAutomatic

Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Target.Address = "$C$5" Or Target.Address = "$C$6" Or Target.Address = "$C$7" Or Target.Address = "$D$5" Or Target.Address = "$D$6" Or Target.Address = "$D$7" Or Target.Address = "$E$5" Or Target.Address = "$E$6" Or Target.Address = "$E$7" Then
  If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
    GoTo Exitsub
  Else: If Target.Value = "" Then GoTo Exitsub Else
    Application.EnableEvents = False
    Newvalue = Target.Value
    Application.Undo
    Oldvalue = Target.Value
      If Oldvalue = "" Then
        Target.Value = Newvalue
      Else
        If InStr(1, Oldvalue, Newvalue) = 0 Then
            Target.Value = Oldvalue & "," & Newvalue
      Else:
        Target.Value = Oldvalue
      End If
    End If
  End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
我的问题:

1) 除了在宏的第10行定义单个单元格,还有什么方法可以定义范围吗?基本上,我使用“或”将C5:E7范围内的所有单元格定义为单个单元格

2) 我无法删除单个逗号分隔的值,因为这样做会产生以下错误。
我必须重新选择整个单元格,然后再次选择值。有什么方法可以只删除单个值吗?

对于Q1:
如果不是应用程序,则Intersect(目标,Me.Range(“C5:E7”))什么都不是,然后
谢谢Robin…这肯定解决了第一个问题。:)