Date: Wed, 19 Sep 2001 16:44:20 -0500 (CDT) From: Mark Jacobson To: 810-022-01@uni.edu Subject: Today's main macro, row coloring code... Hi 022 students, We have a hands-on class on Friday, in WRT 112 lab. Here is the code we developed and talked about today in class. It colors the 1st 20 rows of the worksheet with a randomly chosen color (one of 40 colors) and ensures no row will ever have the same color as the one right above and before it. Sub RowColoring() ' ' 9/19/2001 in class (WRT 105 classroom) demo by Mark Jacobson Static lastColor As Integer ' Static keyword: see pages 426-427 of 21 days book Application.ScreenUpdating = True ' variable persistence For i = 1 To 20 whichRow = i & ":" & i Rows(whichRow).Select theColor = Int(Rnd * 40 + 1) ' theColor is a Variant local variable Do While theColor = lastColor theColor = Int(Rnd * 40 + 1) Loop lastColor = theColor ' remember this rows color number for next time With Selection.Interior .ColorIndex = theColor ' <-- Using theColor variable value! .Pattern = xlSolid -------- End With DoEvents Next i End Sub October 2nd, 2002 ----------------- Group exercise: Write the code for a doPause() Sub that would allow us to slow down the process of coloring each row. Have the doPause() Sub accept as an argument the number of seconds that you want to pause or delay. Where would you put the following statement so that there was a delay AFTER the coloring of a row? doPause( i Mod 6 ) What rows would NOT have any delay and would seem to be colored immediately after the previous row? What rows would have the longest delay or pause occur just before or after they got colored?