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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
| Private Sub cmdLapDataSiswaToXLS_Click()
Dim objExcel As Object
Dim objWBook As Object
Dim objWSheet As Object
Dim areaRef As String
Dim nis(5) As String
Dim nama(5) As String
Dim nilai(5) As Integer
Dim startRow As Long
Dim kolom As Long
Dim initRow As Long
Dim i As Long
nis(0) = "9941224167": nama(0) = "Abdul Fatahurrahman": nilai(0) = 75
nis(1) = "9928712140": nama(1) = "Desy Efriani": nilai(1) = 60
nis(2) = "9930340568": nama(2) = "Durotun Nafisah": nilai(2) = 70
nis(3) = "9941224212": nama(3) = "Bayu Pranoto": nilai(3) = 85
nis(4) = "9941224276": nama(4) = "Hofiruh Sotul'aini": nilai(4) = 95
nis(5) = "9928712137": nama(5) = "Indra Gunawan": nilai(5) = 100
'Create the Excel object
Set objExcel = CreateObject("Excel.application") 'bikin object
'Create the workbook
Set objWBook = objExcel.Workbooks.Add
Set objWSheet = objWBook.Worksheets(1)
With objWSheet
Call formatCell(objWSheet, 1, 1, 1, 4, True, 10, True, xlCenter, xlCenter)
.cells(1, 1) = "DAFTAR NILAI SISWA"
initRow = 3
Call formatCell(objWSheet, initRow, 1, initRow, 4, True, 8, False, xlCenter, xlCenter, True, True)
kolom = 1
.cells(initRow, kolom) = "No."
.Columns(kolom).ColumnWidth = 3.86
kolom = 2
.cells(initRow, kolom) = "N I S"
.Columns(kolom).ColumnWidth = 12.86
kolom = 3
.cells(initRow, kolom) = "Nama"
.Columns(kolom).ColumnWidth = 25.86
kolom = 4
.cells(initRow, kolom) = "Nilai"
.Columns(kolom).ColumnWidth = 6.86
Call formatCell(objWSheet, initRow + 1, 1, initRow + UBound(nis) + 1, 1, False, 8, False, xlCenter, xlCenter, False, True, General) 'NO
Call formatCell(objWSheet, initRow + 1, 2, initRow + UBound(nis) + 1, 3, False, 8, False, xlLeft, xlCenter, False, True) 'NIS DAN NAMA
Call formatCell(objWSheet, initRow + 1, 4, initRow + UBound(nis) + 1, 4, False, 8, False, xlRight, xlCenter, False, True, General) 'NILAI
For i = LBound(nis) To UBound(nis)
If startRow = 0 Then startRow = initRow + i + 1
.cells(initRow + i + 1, 1) = (i + 1)
.cells(initRow + i + 1, 2) = nis(i)
.cells(initRow + i + 1, 3) = nama(i)
.cells(initRow + i + 1, 4) = nilai(i)
Next i
areaRef = convertColRowToAreaRef(objWSheet, 4, startRow, 4, initRow + i)
Call formatCell(objWSheet, initRow + i + 1, 3, initRow + i + 2, 3, False, 8, False, xlRight, xlCenter, True, True) 'Jumlah dan rata-rata
.cells(initRow + i + 1, 3) = "Jumlah"
.cells(initRow + i + 2, 3) = "Rata-rata"
Call formatCell(objWSheet, initRow + i + 1, 4, initRow + i + 1, 4, False, 8, False, xlRight, xlCenter, True, True, General) 'Jumlah
.cells(initRow + i + 1, 4) = "=SUM(" & areaRef & ")"
Call formatCell(objWSheet, initRow + i + 2, 4, initRow + i + 2, 4, False, 8, False, xlRight, xlCenter, True, True, Number) 'Rata-rata
.cells(initRow + i + 2, 4) = "=AVERAGE(" & areaRef & ")"
End With
objExcel.Visible = True
If Not objWSheet Is Nothing Then Set objWSheet = Nothing
If Not objWBook Is Nothing Then Set objWBook = Nothing
If Not objExcel Is Nothing Then Set objExcel = Nothing
End Sub
|