删除以excel

时间:2017-04-05 06:35:13

标签: excel-vba csv dropdown vba excel

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

Here is what my metadata sheet looks like.

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

 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)我无法删除单个逗号分隔值,因为这样做会给我以下错误。A user has restricted values that can be entered into the cell 我需要整个单元格,然后再次选择值。有没有办法可以只删除单个值?

0 个答案:

没有答案
相关问题