Tampilkan postingan dengan label Looping. Tampilkan semua postingan
Tampilkan postingan dengan label Looping. Tampilkan semua postingan

Rabu, 27 Oktober 2021

Do While Loop - buka file yang ada dalam folder


Option Explicit
Sub test()

Dim fileku As String, lokasi As String

lokasi = "D:\Raport Nafa\"
fileku = Dir(lokasi & "*.xlsm")

Do While fileku <> ""
Workbooks.Open lokasi & fileku
fileku = Dir()
Loop

End Sub




Do While Loop

Option Explicit
Sub test()

Dim hitung As Integer
hitung = 1
Do While hitung <= 5
MsgBox "Saya hitung ya " & hitung, vbOKOnly, "info"
hitung = hitung + 1
Loop
End Sub




For Each in next - Menutup Workbook Yang Terbuka

Option Explicit
Sub nutup()

Dim wb As Workbook

For Each wb In Workbooks
If wb.Name <> ThisWorkbook.Name Then
wb.Close
End If
Next wb
End Sub

===================================

Sub nutup()

Dim ws As Worksheet

For Each ws In Worksheets
ws.Visible = xlSheetVisible

Next ws
End Sub


Selasa, 26 Oktober 2021

For Next

Sub test()

Dim i As Integer
For i = 1 To 5

Worksheets.Add
Next i

End Sub
---------------------------------

'kombinasi dengan inputbox

Sub test()
Dim i As Integer
Dim jumlah As Integer

jumlah = InputBox("Masukkan jumlah sheet yang mau ditambahkan?", "Tambah")

For i = 1 To jumlah
Worksheets.Add
Next i


End Sub
----------------------------------


Sub test()
Dim i As Integer
Dim jumlah As Variant

jumlah = InputBox("Masukkan jumlah baris yang akan disembunyikan?", "Jumlah Baris")

If jumlah = "" Then
Exit Sub
End If

For i = 4 To jumlah
Rows(i).Hidden = True
Next i

End Sub

------------------------




Rabu, 20 Oktober 2021

Do While Jika Tidak Sama Dengan Kosong

 Public Sub ExampleDoWhileCalcLoop()

Dim i As Integer

i = 5

Do While Cells(i, 2) <> ""

Cells(i, 3).Value = Cells(i, 2).Value + 30

i = i + 1

Loop

============================

Public Sub DoUntilLoopEx()

Dim i As Integer

i = 1

Do Until IsEmpty(Cells(i, 1))

Cells(i, 1).Value = "info"

i = i + 1

Loop

=============================
Public Sub DoLoopUNTIL()

Dim i As Integer

i = 1
Do
Cells(i, 1).Value = "farmasi"
i = i + 1

Loop Until IsEmpty(Cells(i, 1))

Selasa, 19 Oktober 2021

Exit For

Public Sub ExitForExample()

Dim x As Byte

For x = 1 To 50
Range("B" & x).Select
    If Range("B" & x).Value = "Stop" Then
    Exit For
    ElseIf Range("B" & x).Value = "" Then
    Range("B" & x).Value = "info"
    End If
Next x

Menghitung USIA Excel

=BYROW(D2:D100; LAMBDA(tanggal_lahir;     IF(tanggal_lahir=""; "";         DATEDIF(tanggal_lahir; TODAY(); "y"...