我有一个文件,其中所有数据都位于A列中。此外,我在G列中具有许多唯一标识符。我想根据G列中的标识符对A列中的所有数据进行分组
Sub createRanges()
Dim LastRowAll, LastRowUnique As Integer
Dim x, y
Dim rng As Variant
Range("G3").Select
Selection.End(xlDown).Select
LastRowAll = ActiveCell.Row
Range("A2").Select
Selection.End(xlDown).Select
LastRowUnique = ActiveCell.Row
For Each x In Range("G3:G" & LastRowUnique)
For Each y In Range("A2:A" & LastRowAll)
If IsEmpty(rng) And y = x Then
rng = y.Address(0, 0)
ElseIf y = x Then
rng = rng & "," & y.Address(0, 0)
End If
Next y
rng_formula = "=SUBSTITUTE(x.Value,""-"","""")"
rng_name = Application.Evaluate(rng_formula)
' This yields error 2029
Range(rng).Name = rng_name
With ThisWorkbook
.Names(rng).Delete
End With
Next x
End Sub
为什么以下内容在我的脚本中不起作用;
rng_formula = "=SUBSTITUTE(x.Value,""-"","""")"
rng_name = Application.Evaluate(rng_formula)
如果我检查元素,则 X.value
等于"2016-07-15"
。我需要删除-
,因为在命名范围内不可能使用此字符。
谢谢