Hi all
I've run into an issue when naming ranges within a vba routine, where the time it takes gets exponentially larger as the number of rows in the data to be named is increased.
My dataset is 213 columns wide, i have a standard template which data (varying number of rows) is copied into, and then the macro names each range (1 per column to 213) based on starting at row 4 and ending on the last row of data.
The first datset is around 3000 rows and the naming process takes around 22 seconds.
When i run this on a dataset of 12000 rows i would have expected it to take around 4 times longer, but it is taking greater than 5 minutes (at which point i'm abandoning the process, )
The section of code is as below:
Any ideas on how this could be optimised?
Thank you
I've run into an issue when naming ranges within a vba routine, where the time it takes gets exponentially larger as the number of rows in the data to be named is increased.
My dataset is 213 columns wide, i have a standard template which data (varying number of rows) is copied into, and then the macro names each range (1 per column to 213) based on starting at row 4 and ending on the last row of data.
The first datset is around 3000 rows and the naming process takes around 22 seconds.
When i run this on a dataset of 12000 rows i would have expected it to take around 4 times longer, but it is taking greater than 5 minutes (at which point i'm abandoning the process, )
The section of code is as below:
Code:
Worksheets("Data").ActivateApplication.Calculation = xlCalculationManual
lastcol = ActiveSheet.UsedRange.Columns.Count
lastrow = ActiveSheet.Cells(ActiveSheet.Rows.Count, "A").End(xlUp).Row
For i = 1 To lastcol
If Cells(2, i) <> "" Then
ActiveWorkbook.Names.Add Name:=Cells(2, i).Value, RefersTo:=Worksheets("Data").Range(Cells(4, i), Cells(lastrow, i))
End If
Next i
Any ideas on how this could be optimised?
Thank you