Please abbreviation a EXCEL macro, so that a specified number of cells that turns pale yellow.

Users questions: A sheet in the arbitrarily selected a range, such as A1-H8 in this range, so that a specified number of random cell turns pale yellow. Cell position is random, the number of cells = the total number of selected cell * 2 * 5. If the calculated number of cells is not an integer, the rounding Into rounded. Select All or select a row or column error, did not seem to change. Select all or selected rows or columns error. Please increase the code, so that selected area is less than four cells, or more than 100 cell does not run this macro. This is not the error. I do not have access less than 4 cells, or more than 100 Cell case.
Experts answer: code below PrivateSubWorksheet_SelectionChange (ByValTargetAsRange) Dima%, b%, c%, c1%, d%, d1%, n%, x% , Y%, x1%, y1%, i% IfTarget.Count = 1ThenExitSub 'when selecting a cell when only the end of ElseCells.Interior.ColorIndex = xlNone' will remove all the cell color a = Target.Row: b = Target.Column 'access to the ranks of the initial cell marked IfTarget.Rows.Count = 65534ThenExitSubc1 = Target.Rows.Count: d1 = Target.Columns.CountIf(c1 =4Andd1=1)Or(d1 =4Andc1=1)Or(c1 =2Andd1 =2)ThenExitSubc=a+c1-1:d=b+d1-1 Ranks marked the end of the cell n = Round (Target.Count * 2 * 5) 'calculate the number of cells should change color Fori = 1Tonx = Int ((c-a +1) * Rnd ()) + a: y = Int ( (d-b +1) * Rnd ()) + b 'Randomly generated within the ranks of the specified standard Ifx x1Andy y1Then' xy at the same time to prevent duplication of Cells (x, y). Interior.ColorIndex = 36 'will meet the conditions set light yellow cell x = x1: y = y1' is sentenced Xy-off value is repeated to prepare Elsei = i-1 'when xy Repeat the same time increase the time when i-1 loop EndIfNextEndIfEndSub changes have been good according to your requirements, you then see if the problem continues to point out what accessories: Book1.xls
  • This information provided by the users.Thanks!