I create a dynamic named range for certain cells in one of my sheets. The problem is when user changes the name of that sheet. So, I decide to make VBA code which will run when sheet changes, but I can not make it done right.
My dynamic named range is: MyBooks
and its formula is: =OFFSET('Book list'!$A$1;0;0;COUNTA('Book list'!$A$1:$A$500);1)
I also made this code:
This code gives error 1004. What is wrong with above code?
I run the code through Step Into and create Add watch and find that the formula in code have exactly the same string value as my original formula but it is still not working.
Any help?
My dynamic named range is: MyBooks
and its formula is: =OFFSET('Book list'!$A$1;0;0;COUNTA('Book list'!$A$1:$A$500);1)
I also made this code:
Code:
Dim BooksName As String
For Each WS In Worksheets
If WS.CodeName = "Books" Then
BooksName = WS.Name
Exit For
End If
Next WS
ActiveWorkbook.Names.Add Name:="MyBooks", RefersTo:= _
"=OFFSET('" & BooksName & "'!$A$1;0;0;COUNTA('" & BooksName & "'!$A$1:$A$500);1)"
This code gives error 1004. What is wrong with above code?
I run the code through Step Into and create Add watch and find that the formula in code have exactly the same string value as my original formula but it is still not working.
Any help?
Last edited: