0

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

3
  • Isn't this more or less the same question Commented Sep 28, 2018 at 10:01
  • Write Application.EnableAnimations = False after you declare the Sub and there would be no need to avoid 10% of the calculations - it will fly. Commented Sep 28, 2018 at 10:02
  • @Vityata It is more like 80% of the of the values, i unfortunately already have that set ot false Commented Sep 28, 2018 at 10:04

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.