0

After copying a template sheet via vba I need to set two cells for start and end dates that use data validation referencing a sheet scoped named range for its formula. To do this I need the first and last entries for the named range.

To test the code before setting the cell data I have the following:

Debug.Print "Charts 1 Start " & Sh.Names("ProjectTemplateDates").RefersToRange(1, 1)

Debug.Print "Charts 1 End " & Sh.Names("ProjectTemplateDates").RefersToRange.End(xlDown).Value

The first Debug.Print gives me the correct first entry:

Charts 1 Start 01/09/2017

however the last entry code gives me:

Charts 1 End 100000

When I was expecting it to give me Charts 1 End 01/03/2023. Should I be doing something different to find the last entry in the named range?

1 Answer 1

1
With sh.Names("ProjectTemplateDates").RefersToRange Debug.Print "Charts 1 Start " & .Cells(1, 1) Debug.Print "Charts 1 End " & .Cells(.Rows.Count + 1, 1).End(xlUp).Value End With 
Sign up to request clarification or add additional context in comments.

2 Comments

I think this would have worked if the data was in row format (something I forgot) so I ended up with the following working solution for the column based named range - Debug.Print "Charts 1 End" & .Cells(1, .Columns.Count).End(xlUp).Value
@AutomationMonkey: If data are on a single row, then use: Debug.Print "Charts 1 End" & .Cells(1, .Columns.Count + 1).End(xlToLeft).Value

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.