I'm trying to resize an existing named range by adding some rows and want to keep the range name the same. I'm using the example in the book "Excel 2007 VBA, Programmer's Reference" (page 104) which uses Resize and Name. When I print the row and column count before and after the resize, they show the same values. Is there a bug in "resize" or is the example in the book wrong? What is the best way to resize an existing named range while keeping the range name the same?
Code used to show example:
Code:
Option Explicit
Option Base 1
Dim rng As Range
Dim wkb As Workbook
Dim wks As Worksheet
Sub RangeTest()
Set wkb = Workbooks(ActiveWorkbook.Name)
Set wks = wkb.Sheets("TestSheet1")
Set rng = wks.Range("TestRng1")
Debug.Print "Before resize:"
Debug.Print "#rows, #cols = ", rng.Rows.Count, rng.Columns.Count
rng.Resize(20).Name = "TestRng1"
Debug.Print "After resize:"
Debug.Print "#rows, #cols = ", rng.Rows.Count, rng.Columns.Count
End Sub