Hello Geo45,
Here is the updated macro. The logic is straightforward. The macro uses arrays to manipulate the data because it is so much faster than copy and paste. With large arrays of data, you want to use arrays. When a range is assigned to a variable that is a Variant type, the variable is dimensioned as a 2-D array with the same number of rows and columns present in the Range. The Range values are copied into the new array. The first index of the array is at {1,1}.
A new array is dimensioned to hold the output data. This array must be large enough to hold all of the new data rows and columns. The number of needed rows is calculated by multiplying the rows in the "Materials" column by the number of rows in either the "Tag" or "Text" columns, since they are the same length. If they were not then the longer of the two would be used.
The number of columns is three: Materials, Tag, Text. The variable InfoOut, which is a Variant type, is redimensioned to the number of rows needed and 3 columns wide. This array is loaded using two loops. An outer loop, j, is used for the rows and an inner loop, k, is used for the columns. An independent row counter, the variable n, is used as the row index for the new array InfoOut. The array InfoIn holds the Range's values. The first column is "Material", the second column is "Tag" and the third column is "Text".
After the InfoOut has been loaded, it is output to cell "E2". This is 4 columns to the left of column "A2". Cell "E2" is used as the starting point for the output range. The range is set to match the number of rows and columns in the array InfoOut. Assigning a Variant array to a Range's value property will load the Range with those values. This is reverse of what was done in paragraph 1.
[]Updated Macro Code[/b]
Bookmarks