Date: Mon, 15 Sep 2003 10:24:56 -0500 (CDT) From: Mark Jacobson To: 810-022-01@uni.edu Subject: [810-022-01] Offset() to avoid extra variable... Hi 022 students, With the 2nd to last slide on the Excel birthday problem slide show, on the class web page: lastCellValue = -99 could be removed and lastCellValue = theCell.Value could also be removed These two statements are NOT NEEDED, if you take further advantage of the .Offset() idea and modify the If statement from If theCell.Value = lastCellValue Then to If theCell.Value = theCell.Offset(-1, 0).Value Then Note that theCell.Offset(-1, 0).Value refers to the number in the cell just above theCell. -1 means previous row, 0 means same column. And finally, here is what ReportResult (hadRepeat) looks like: ------------------------ Note that ReportResult is just TallyTheResult() modified, and that ReportResult Sub doesn't have as much work to do. See VBA code for Version #2 slide to study TallyTheResult() Sub. Sub ReportResult( hadRepeat As Boolean ) If hadRepeat Then Range("D2").Value = Range("D2").Value + 1 ' with repeats Else Range("E2").Value = Range("E2").Value + 1 ' without repeats End If End Sub or........ Sub ReportResult( hadRepeat As Boolean ) If hadRepeat Then Range("D2").Value = Range("D2").Value + 1 ' count with repeats End If Range("E2").Value = Range("E2").Value + 1 ' total overall runs End Sub The above should help as you study the powerpoint point presentation. Mark