Sub Ñëó àéíûå èñëà1 Dim filePath As String filePath St Ñëó àéíûå èñëà

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
Sub Ñëó÷àéíûå×èñëà1()
Dim filePath As String
filePath = "C:\St\Ñëó÷àéíûå ÷èñëà.xls"
Dim sheetName As String
sheetName = "Ñëó÷. ÷èñëà"
Dim myWorkbook As Workbook
Set myWorkbook = Workbooks.Open(filePath)
Dim sheetNumber As Integer
sheetNumber = -1
For i = 1 To myWorkbook.Worksheets.Count
If myWorkbook.Worksheets(i).Name = sheetName Then
sheetNumber = i
Exit For
End If
Next i
If sheetNumber = -1 Then
MsgBox "Ëèñòà ñ èìåíåì 'Ñëó÷. ÷èñëà' íå îáíàðóæåíî"
Exit Sub
End If
Dim mySheet As Worksheet
Set mySheet = myWorkbook.Worksheets(sheetNumber)
Dim firstEmptyLine As Integer
firstEmptyLine = 1
While Trim(mySheet.Cells(firstEmptyLine, 1).Value) <> ""
firstEmptyLine = firstEmptyLine + 1
Wend
For i = firstEmptyLine To firstEmptyLine + 5
mySheet.Cells(i, 1).Value = Int(100 * Rnd())
Next i
myWorkbook.SaveAs Filename:=filePath
MsgBox "Ñëó÷àéíûå ÷èñëà ðàçûãðàíû!"
End Sub