Excel VB: add Cell to existing Name
-
24-06-2021 - |
문제
I'm trying to add a Cell to an existing Name via VB.
My best Attempt looks like this:
Tabelle1.Names("delCase").RefersTo = Tabelle1.Names("delCase").RefersTo + ";" + Target.Address
But this prompts a
Application- or objectdefined Error
해결책
Try this (TRIED AND TESTED)
Union(Tabelle1.Range("delCase"), Target).Name = "delCase"
다른 팁
Instead of trying to assign a string to RefersTo
, you can directly assign a Range
(as RefersTo
is of type variant
). Changing your line slightly to:
Tabelle1.Names("delCase").RefersTo = Tabelle1.Range("delCase;" & Target.Address)
Then works as expected.
If you'd like a more elegant way to do this, try:
Tabelle1.Range("delCase;" & Target.Address).Name = "delCase"
제휴하지 않습니다 StackOverflow