Originally Posted by
ericwcf
...after copy number 8, 15 and up to 7th number from Range(“A1:AS1”) to Range(“A4:G4”), so
may I know how do you remove the number 8, 15, etc that was just copied from Range(“A1:AS1”).
I confess I don't really understand the above.
What I would say is that is that if you don't understand some code it's a good idea to "step through" it via F8 in VBE - use the Locals Window etc to see what's going on regards specific variables etc as the code progresses.
For more info. re: "debugging" code see: http://www.cpearson.com/excel/Debug.htm
In terms of explanation (as best I can)...
The code essentially takes the values in A1:AS1 and populates an Array with only the non-blank values (ie all blanks are removed).
In your sample this means that the above generates an Array containing 40 items (0 to 39) - the 5 blanks being disposed of.
The code establishes the position of the "start" number within the Array:
(adjusting return by 1 to account for 0 based Array - ie Match 1 is item 0)
We then iterate 7 times (bCount 1 to 7) to retrieve the appropriate values given start position.
We use a MOD construct based on present bMatch value and interval of 7 to determine the appropriate Item number for each iteration:
The selected number is added to the previous numbers selected by virtue of an incrementing string variable:
once the 7 iterations are complete we then take the string of 7 numbers (strY), remove the leading space before subsequently splitting the string by Space character and returning the now 7 individual results to A4:G4
(the numbers are stored in the initial array and indeed strY as strings ["1" etc] - we use the numberformat and value = value route to coerce the final 7 values back to numbers)
Bookmarks