又改了一下,我想你用的是2003,而我是在2007中测试的.你再试试吧.另外你要将数字改成其他指定数字,可以用大米的方法吧.你试试好了. sub random() dim a as integer dim b as integer a = int(rnd() * 500) + 1 b = int(rnd() * 8) + 1 for x = 1 to 2000 do while cells(a, b).value <> "" a = int(rnd() * 500) + 1 b = int(rnd() * 8) + 1 loop cells(a, b) = int(rnd() * 15) + 1 do while worksheetfunction.countif(range("a" & a & ":h" & a), cells(a, b)) > 1 cells(a, b) = int(rnd() * 15) + 1 loop next for x = 1 to 1200 do while cells(a, b).value <> "" a = int(rnd() * 500) + 1 b = int(rnd() * 8) + 1 loop cells(a, b) = int(rnd() * 21) + 16 do while worksheetfunction.countif(range("a" & a & ":h" & a), cells(a, b)) > 1 cells(a, b) = int(rnd() * 21) + 16 loop next for x = 1 to 800 do while cells(a, b).value <> "" a = int(rnd() * 500) + 1 b = int(rnd() * 8) + 1 loop cells(a, b) = int(rnd() * 14) + 37 do while worksheetfunction.countif(range("a" & a & ":h" & a), cells(a, b)) > 1 cells(a, b) = int(rnd() * 14) + 37 loop next for x = 1 to 500 range("a" & x & ":h" & x).sort key1:=range("a" & x), order1:=xlascending, header:= _ xlguess, ordercustom:=1, matchcase:=false, orientation:=xllefttoright, _ sortmethod:=xlpinyin, dataoption1:=xlsortnormal next end sub