Langkah-langkahnya adalah sebagai berikut:
1. Buatlah terlebih dahulu file contoh dengan data di Sheet1 seperti berikut:
2. Untuk contoh ini, kita buat file yang sederhana dulu, yang penting paham dulu fungsinya. Buat Sheet2 dengan data seperti berikut:
3. Buka VB Editor di file excel anda
4. Pada VB Editor, klik view, lalu klik Project Explorer
3. Pilih Sheet2 pada file terkait (Double klik bagian Sheet2 pada nama file yg anda buat)
4. Copy paste code berikut ke Module tersebut
-----------------------------------------------------------------------------------
'<<>>
Option Explicit
Private Sub Worksheet_Activate()
Dim HiddenRow&, RowRange As Range, RowRangeValue&
'*****************************
'<>
Const FirstRow As Long = 4
Const LastRow As Long = 20
'<>
Const FirstCol As String = "B"
Const LastCol As String = "G"
'*****************************
ActiveWindow.DisplayZeros = False
Application.ScreenUpdating = False
For HiddenRow = FirstRow To LastRow
'(we're using columns B to G here)
Set RowRange = Range(FirstCol & HiddenRow & _
":" & LastCol & HiddenRow)
'sums the entries in cells in the RowRange
RowRangeValue = Application.Sum(RowRange.Value)
If RowRangeValue <> 0 Then
'there's something in this row - don't hide
Rows(HiddenRow).EntireRow.Hidden = False
Else
'there's nothing in this row yet - hide it
Rows(HiddenRow).EntireRow.Hidden = True
End If
Next HiddenRow
Application.ScreenUpdating = True
End Sub
--------------------------------------------------------
5. Close VB Editor.