' Friday, October 3rd, 2008 810:022 StudioIT 2 lab class Function randomBirthday() As Integer b = Int(Rnd * 365 + 1) randomBirthday = b End Function Sub loops() For i = 1 To 100 Cells(i, i).Value = i ^ 2 Next i End Sub Sub ConvertToValues() Selection.Copy Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _ :=False, Transpose:=False Application.CutCopyMode = False End Sub Sub Birthday() ' Range("A1").Select ActiveCell.FormulaR1C1 = "Birthday" Range("A2").Select ActiveCell.FormulaR1C1 = "=randomBirthday()" Selection.AutoFill Destination:=Range("A2:A24"), Type:=xlFillDefault Range("A2:A24").Select Application.Run "Book1!ConvertToValues" ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Clear ActiveWorkbook.Worksheets("Sheet2").Sort.SortFields.Add Key:=Range("A2"), _ SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortNormal With ActiveWorkbook.Worksheets("Sheet2").Sort .SetRange Range("A2:A24") .Header = xlNo .MatchCase = False .Orientation = xlTopToBottom .SortMethod = xlPinYin .Apply End With Range("B1").Select ActiveCell.FormulaR1C1 = "Repeated" Range("B3").Select ActiveCell.FormulaR1C1 = "=IF(R[-1]C[-1]=RC[-1],""Repeat"",""no"")" Selection.AutoFill Destination:=Range("B3:B24"), Type:=xlFillDefault Range("C1").Select updateCounts End Sub Sub updateCounts() hadRepeat = False For Each theCell In Range("B3:B24") If theCell.Value = "Repeat" Then hadRepeat True End If Next theCell If hadRepeat Then Range("D3").Value = Range("D3").Value + 1 End If Range("E3").Value = Range("E3").Value + 1 End Sub