문제

I have searched for a solution but can't seem to find one. If one exists, please point me to it. The question is how do I name a range in VBA.

    wrkSheet.Range("A1").Name = "Test"

Works fine but as soon as I change it to

    wrkSheet.Range("A1:B2").Name = "Test"

gives me problems. Note, wrkSheet is a worksheet object that is defined earlier.

Thanks

도움이 되었습니까?

해결책

you can use this to name a range. Not sure why wrkSheet is a string as it should be a worksheet object

Dim ws As Worksheet
Dim r As Range
Set ws = Sheets(1)
Set r = ws.Range("A1:B2")
r.Name = "test"

다른 팁

You're not naming a range there... you giving values to a excel range of cells... To name a range you do

range = wrkSheet.Range("A1:B2").Name

Then you can do range(1,1) = "test" for example.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top