I have the following data structure:
+-----------------+---------------+
| ExcelRangedName | Default Value |
+-----------------+---------------+
| Name1 | |
| Name2 | FALSE |
| Name3 | TRUE |
| Name4 | 0 |
| Name5 | Alpha |
| Name6 | |
| Name7 | |
| Name8 | |
| … | … |
+-----------------+---------------+
Note that the "ExcelRangedName" column is in fact thousands of rows.
I have a macro which will set the rangename of "ExcelRangedName" column to the corresponding "Default Value" column. For simplicity I have called the above table "RangeMappingTbl":
For i = 1 To MaxRowCount
Range(Range("RangeMappingTbl").Cells(i, 1).Value).Value = Range("RangeMappingTbl").Cells(i, 2).Value
Next i
Where MaxRowCount is the maximum number of rows entered in the table.
Now, this is fairly efficient because the range name value may already be equal to the default value and the above macro will simply replace that value. I want to include a check it does equal the value, then skip - HOWEVER, doing this with VBA will not speed up the process, as the inefficiency comes from calling the the range name, i.e. everytime I call:
Range(Range("RangeMappingTbl").Cells(i, 1).Value).Value
the macro will slow down.
I am trying to have a "check" column on excel, which returns TRUE if the value of the range name is already equal to the default value. The macro will then look at this column and only repeat if the column value is FALSE. However, the only option I have of doing this is using the INDIRECT function, which is very slow. Does anyone have a way around this, or a better solution which does not use
Range(Range("RangeMappingTbl").Cells(i, 1).Value).Value
As an example, if the ranged name "Name5" equals "Alpha" then the macro does not need to replace it and can simply skip over that value.
Thanks
Application.EnableAnimations = Falseafter you declare theSuband there would be no need to avoid 10% of the calculations - it will fly.