Pak Kid.
seperti ini :
Sub Input_Summary2()
Dim shR, shS, shM, shO, sh1, shM2 As Worksheet
Dim rng1, rng2, rng3 As Range
Dim r, c, t, w As Long
Dim psa, psn, pkg, wkg As Long
Dim va1, va2, va3 As Long
Dim dbl As Double
Set shS = Worksheets("Simulasi Aktual")
Set shM = Worksheets("MonteCarlo")
Set shR = Worksheets("Random")
Set shO = Worksheets("OUTPUT")
Set sh1 = Worksheets("Sheet1")
Set shM2 = Worksheets("MonteCarlo2")
Set rng1 = Worksheets("Random").Range("I2:J1001")
Set rng2 = Worksheets("Random").Range("W2:X101")
Set rng3 = Worksheets("Random").Range("T2:U101")
'---- aktif sheet
shM2.Activate
Range("B10:C610").ClearContents
Range("E10:I610").ClearContents
Range("K10:K610").ClearContents
Range("M10:O610").ClearContents
Range("K1:N1").ClearContents
dbl = Timer
Cells(1, 13).Value = Time
Cells(1, 6).Value = "Sumary2"
'ini buat copy randbetween
Range("AP11:AP610").Copy
Range("J11:J610").PasteSpecial xlValue
Application.CutCopyMode = False
Range("AR11:AR610").Copy
Range("L11:L610").PasteSpecial xlValue
Application.CutCopyMode = False
Cells(11, 2).Select
Application.Calculation = xlCalculationAutomatic
'Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
psa = shS.Cells(9, 2)
'psa = shM.Cells(100, 7)
With Application.WorksheetFunction
'For C=3 to 8
For c = 3 To 3
'For r =7 to 29
For r = 7 To 7
Range("H11:I3511").ClearContents
psn = shO.Cells(r, 2)
pkg = shO.Cells(6, c)
'For t = 11 to 3510
For t = 11 To 610
Cells(t, 2).Value = psa
' Cells(t, 4).Value = .RandBetween(1, 1000)
If Cells(t, 4) > 0 Then
Cells(t, 5).Value = .VLookup(Cells(t, 4), rng1, 2, False)
End If
If (Cells(t, 2) + Cells(t, 3)) < Cells(t, 5) Then
Cells(t, 6).Value = (Cells(t, 5) - Cells(t, 3) - Cells(t, 2)) *
Cells(6, 3)
End If
psa = Cells(t, 2) + Cells(t, 3) - Cells(t, 5)
Cells(t, 7).Value = psa
If Cells(t, 7).Value < psn Then
Cells(t, 8).Value = "Pesan"
Cells(t, 9).Value = pkg
' Cells(t, 10).Value = .RandBetween(1, 100)
' Cells(t, 12).Value = .RandBetween(1, 100)
'=====================
Cells(t, 11).Value = .VLookup(Cells(t, 10), rng2, 2, False)
w = Cells(t, 11).Value + t
Cells(t, 15).Value = w
wkg = Cells(w, 3).Value
Cells(w, 3).Value = wkg + pkg
Cells(t, 13).Value = .VLookup(Cells(t, 12), rng3, 2, False)
'=======================
ElseIf Cells(t, 7) > psn Then
' Cells(t, 8).Value = ""
' Cells(t, 9).Value = 0
Cells(t, 10).Value = 0
' Cells(t, 11).Value = 0
Cells(t, 12).Value = 0
' Cells(t, 13).Value = 0
End If
' If Cells(t, 10) = 0 Then
' ElseIf Cells(t, 10) > 0 Then
' Cells(t, 11).Value = .VLookup(Cells(t, 10), rng2, 2, False)
' w = Cells(t, 11).Value + t
' Cells(t, 21).Value = w
' wkg = Cells(w, 3).Value
' Cells(w, 3).Value = wkg + pkg
' End If
' If Cells(t, 12) > 0 Then
' Cells(t, 13).Value = .VLookup(Cells(t, 12), rng3, 2, False)
' End If
If Cells(t, 9) = 0 Then
Cells(t, 14).Value = (Cells(t, 3) * Cells(5, 3)) + Cells(t,
6) + (Cells(t, 7) * Cells(3, 3))
ElseIf Cells(t, 9) > 0 Then
Cells(t, 14).Value = (Cells(t, 9) * Cells(t, 13)) +
(Cells(t, 3) * Cells(5, 3)) _
+ Cells(t, 6) + (Cells(t, 7) * Cells(3, 3))
+ Cells(4, 3)
End If
Next t
Cells(t, 14).Value = .Sum(Range(Cells(11, 14), Cells(t, 14)))
shO.Cells(r, c).Value = shM2.Cells(t, 14)
Next r
Next c
End With
Application.ScreenUpdating = True
' MsgBox "Proses Selesai", vbInformation
dbl = Timer - dbl
Cells(1, 11).Value = dbl
Cells(1, 14).Value = Time
End Sub
ini yg pertama ---- dari percobaan kedua.
dibawah ini : yg kedua dari percobaan kedua.
bedanya untuk randbetween dan vlookup --- saya ambil dari sebelah
kanannya.
If Cells(t, 27).Value < psn Then
Cells(t, 28).Value = "Pesan"
Cells(t, 29).Value = pkg
' Cells(t, 30).Value = .RandBetween(1, 100)
' Cells(t, 32).Value = .RandBetween(1, 100)
Cells(t, 30).Value = Cells(t, 30).Offset(0, 12)
Cells(t, 31).Value = Cells(t, 31).Offset(0, 12)
Cells(t, 32).Value = Cells(t, 32).Offset(0, 12)
Cells(t, 33).Value = Cells(t, 33).Offset(0, 12)
w = Cells(t, 31).Value + t
Cells(t, 35).Value = w
ElseIf Cells(t, 27) > psn Then
' Cells(t, 28).Value = ""
' Cells(t, 29).Value = 0
' Cells(t, 30).Value = 0
' Cells(t, 31).Value = 0
' Cells(t, 32).Value = 0
' Cells(t, 33).Value = 0
End If
-------------> hasil percobaan kedua dari kedua --- lebih lambat .
sampai setengah putus asa.
baru saya coba ganti
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = False
' kan cuma ada 4 kemungkinan saja .
ternyata yg sebelumnya hanya di kasih
Application.Calculation = xlCalculationAutomatic ------> menjadi : manual
-------- hasil nya nga pakai lama .
setelah selesai ----------- saya masukan formula xl biasa ---------- dan
ternyata hasil nya sama .
didalam nya terkandung ------------ nilai total per baris .
dan ada ginian .
If t = 11 Then
Cells(t, 2).Value = psa
ElseIf t > 11 Then
Cells(t, 2).Value = Cells(t - 1, 7)
End If
---------------------------
dibawah ini percobaan yg pertma.
Sub Input_Summary1()
Dim shR, shS, shM, shO, sh1 As Worksheet
Dim rng1, rng2, rng3 As Range
Dim r, c, t, w As Long
Dim psa, psn, pkg, wkg As Long
Dim has1, has2 As Variant
Dim va1, va2, va3 As Long
Dim dbl As Double
Set shS = Worksheets("Simulasi Aktual")
Set shM = Worksheets("MonteCarlo")
Set shR = Worksheets("Random")
Set shO = Worksheets("OUTPUT")
Set sh1 = Worksheets("Sheet1")
Set rng1 = Worksheets("Random").Range("I2:J1001")
Set rng2 = Worksheets("Random").Range("W2:X101")
Set rng3 = Worksheets("Random").Range("T2:U101")
shM.Activate
dbl = Timer
Cells(1, 13).Value = Time
'Application.Calculation = xlCalculationAutomatic
Application.Calculation = xlCalculationManual
Application.ScreenUpdating = False
Range("B10:O3500").ClearContents
psa = shS.Cells(9, 2)
'psa = shM.Cells(100, 7)
With Application.WorksheetFunction
'For c = 3 To 8
For c = 3 To 3
'For r = 7 To 29
For r = 7 To 8
psn = shO.Cells(r, 2)
pkg = shO.Cells(6, c)
'For t = 11 to 3495
For t = 11 To 3495
Cells(t, 4).Value = .RandBetween(1, 1000)
Cells(t, 10).Value = .RandBetween(1, 100)
Cells(t, 12).Value = .RandBetween(1, 100)
If t = 11 Then
Cells(t, 2).Value = psa
ElseIf t > 11 Then
Cells(t, 2).Value = Cells(t - 1, 7)
End If
If Cells(t, 4) > 0 Then
Cells(t, 5).Value = .VLookup(Cells(t, 4), rng1, 2, False)
End If
If (Cells(t, 2) + Cells(t, 3)) < Cells(t, 5) Then
Cells(t, 6).Value = (Cells(t, 5) - Cells(t, 3) - Cells(t, 2)) *
Cells(6, 3)
End If
Cells(t, 7).Value = Cells(t, 2) + Cells(t, 3) - Cells(t, 5)
If Cells(t, 7).Value < psn Then
Cells(t, 8).Value = "Pesan"
Cells(t, 9).Value = pkg
ElseIf Cells(t, 7) > psn Then
Cells(t, 8).Value = ""
Cells(t, 9).Value = 0
Cells(t, 10).Value = 0
Cells(t, 11).Value = 0
Cells(t, 12).Value = 0
Cells(t, 13).Value = 0
End If
If Cells(t, 7) > psn Then
ElseIf Cells(t, 7) <= psn Then
Cells(t, 11).Value = .VLookup(Cells(t, 10), rng2, 2, False)
w = Cells(t, 11).Value + t
Cells(t, 15).Value = w
wkg = Cells(w, 3).Value
If w <= 3495 Then
Cells(w, 3).Value = wkg + pkg
End If
End If
If Cells(t, 12) > 0 Then
Cells(t, 13).Value = .VLookup(Cells(t, 12), rng3, 2, False)
End If
If Cells(t, 9) = 0 Then
Cells(t, 14).Value = (Cells(t, 3) * Cells(5, 3)) + Cells(t,
6) + (Cells(t, 7) * Cells(3, 3))
ElseIf Cells(t, 9) > 0 Then
Cells(t, 14).Value = (Cells(t, 9) * Cells(t, 13)) +
(Cells(t, 3) * Cells(5, 3)) _
+ Cells(t, 6) + (Cells(t, 7) * Cells(3, 3))
+ Cells(4, 3)
End If
has2 = has2 + Cells(t, 14)
If t = 3495 Then
has1 = .Sum(Range(Cells(11, 14), Cells(t, 14)))
Cells(3496, 14).Value = .Sum(Range(Cells(11, 14), Cells(t, 14)))
shO.Cells(r, c).Value = Cells(3496, 14)
End If
Next t
shO.Cells(r + 28, c).Value = has2
has1 = 0
has2 = 0
Next r
Next c
End With
Application.ScreenUpdating = True
' MsgBox "Proses Selesai", vbInformation
Application.Calculation = xlCalculationAutomatic
dbl = Timer - dbl
Cells(1, 11).Value = dbl
Cells(1, 14).Value = Time
End Sub
------------ disitu full VBA.
cuma masih ada yg aneh .
bila di running terlalu cepat :
yg ini jadi kacau balau :
w = Cells(t, 11).Value + t
Cells(t, 15).Value = w
wkg = Cells(w, 3).Value
If w <= 3495 Then
Cells(w, 3).Value = wkg + pkg
Kalau step by step --- normal.
seandai saya buat bikin range : inputan dari nilai w itu
Cells(t, 15).Value = w
maka saya akan mengunakan sumifs
dan yg dibawah ini tidak di perlukan lagi
If w <= 3495 Then
Cells(w, 3).Value = wkg + pkg
Salam
Lukman
2014-10-01 20:37 GMT+07:00 'Mr. Kid' [email protected] [belajar-excel] <
[email protected]>:
>
>
> :)
>
> Saya ndak tahu dalam cell ada yang menggunakan fungsi randbetween atau
> ndak. Poin pentingnya, setting kalkulasi manual atau automatic tidak akan
> mengubah sifat fungsi RandBetween. Jika fungsi ini dipakai dalam sebuah
> cell alias di cell tersebut berisi formula berbunyi =Randbetween( bla , bli
> ) ataupun fungsi-fungsi yang bersifat volatile lainnya, maka cell tersebut
> akan berubah nilainya begitu setting kalkulasi dikembalikan menjadi
> automatic.
>
> Secara umum, cerita proses yang berkaitan dengan cell berfungsi volatile
> seperti RandBetween adalah sebagai berikut :
> > jika di cell 1 diberi fungsi RandBetween : (di cell 1 ada formula
> berbunyi =RandBetween( bla , bli )
> a. Nilai cell 1 awal adalah x1,
> b. VBA mengubah setting kalkulasi ke manual,
> c. VBA hitung berdasar nilai hasil cell 1, yaitu nilai x1
> d. VBA tulis hasil hitungannya ke sebuah cell 2,
> e. VBA mengubah setting kalkulasi ke automatic lagi,
> f. nilai di cell 1 sudah berubah menjadi x2 yang kemungkinan besar
> x1<>x2
>
> > jika di cell 1 *tidak ada* fungsi randbetween : (di cell 1 berisi nilai
> konstan atau malah masih kosong)
> a. VBA mengubah setting kalkulasi ke manual,
> b. VBA pasang formula di cell 1 berupa fungsi RandBetween (cell 1
> berisi formula randbetween jadinya)
> c. Nilai cell 1 awal adalah x1 (saat kalkulasi set manual),
> d. VBA hitung berdasar nilai hasil cell 1, yaitu nilai x1
> e. VBA tulis hasil hitungannya ke sebuah cell 2,
> f. VBA mengubah setting kalkulasi ke automatic lagi,
> g. nilai di cell 1 sudah berubah menjadi x2 yang kemungkinan besar
> x1<>x2
>
> > jika di cell 1 *tidak ada* fungsi randbetween dan semua proses
> dilakukan di dalam VBA (malah ndak perlu set kalkulasi ke manual)
> a. VBA tulis ke cell 1 hasil worksheetfunction randbetween
> b. VBA ambil nilai dari cell 1, misal bernilai x1
> c. VBA hitung berdasar nilai cell 1, yaitu nilai x1
> d. VBA tulis hasil hitungannya ke sebuah cell 2,
> e. nilai di cell 1 tetaplah x1
>
> Wassalam,
> Kid.
>
>
>
> 2014-10-01 20:57 GMT+10:00 lkm jktind [email protected] [belajar-excel]
> <[email protected]>:
>
>
>>
>> Pak Kid.
>>
>> Terima kasih.
>>
>> sudah kutemukan masalahnya .
>> ternyata didalam VBA ada : Application.Calculation =
>> xlCalculationAutomatic
>> kacau.
>>
>> Hasilnya :
>> dengan formula tetap menempel di work sheet , dan pakai automatic : 7.338
>> detik
>> dengan formula tetap menempel di work sheet , dan dicentang automatic :
>> 635 detik --- di excel - posisi manual
>> dengan formula full di VBA Application.Calculation = xlCalculationManual
>> : beberapa detik saja.
>> (dibawah 2 detik) ---- sebanding dengan cpu usage nya dipakai semua .
>>
>> dengan data 3495 ---- bila ini di loop lagi 23 X 6 --- masih nga ada
>> artinya.
>>
>> mungkin harus saya biasakan . --- sebelum masuk ke perhitungan dengan
>> full VBA .
>> Application.Calculation = xlCalculationManual.
>>
>> menjelang akhir baru di beri :
>> Application.Calculation = xlCalculationAutomatic
>>
>> sedangkan : screen up to dating --- true atau false . ---selisih
>> waktunya beda dikit saja.
>>
>> telah saya cross check : hasil dari full vba --------- lalu saya input
>> formula dari excel .
>> kecuali randbetween --- yg tidak di ganggu ------. dan hasil akhirnya
>> sama .
>> boleh kah saya artikan : bahwa formula yg saya gunakan di VBA --- sudah
>> sesuai dengan di excel .
>>
>>
>>
>> Salam
>>
>>
>> Lukman
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> 2014-10-01 3:41 GMT+07:00 'Mr. Kid' [email protected] [belajar-excel] <
>> [email protected]>:
>>
>>
>>>
>>> Pak Lukman,
>>>
>>> Semua fitur Excel ketika digunakan dalam VBA, akan bekerja lebih lamban,
>>> karena dibutuhkan proses eksekusi baris script VBA.
>>> Untuk lama proses sampai 1700 detik pada iterasi yang sangat banyak
>>> (lebih dari 500K step iterasi) mungkin terhitung wajar. Untuk terasi
>>> dibawah 500K, berarti ada yang kurang pas antara otomasi dengan sistem
>>> simulasinya. Penjelasan sistem simulasi lengkap beserta dasar teori
>>> pemilihan komponen simulasinya perlu diketahui lebih dahulu sebelum
>>> menyusun otomasinya.
>>>
>>> Diemail Anda dikatakan ada penggunaan RandBetween dan vLookUp. Maka
>>> harus dipertanyakan lebih dulu, apakah simulasinya akan membentuk langsung
>>> 1 dataset (series waktu) sekaligus atau satu per satu setiap waktu sampai
>>> seluruh dataset terbentuk. Maksudnya, harus digenerate langsung dari
>>> tanggal ke-1 sampai tanggal ke-1000 atau tanggal ke-1 selesai lalu muncul
>>> tanggal ke-2 dst sampai tanggal ke-1000.
>>>
>>> Kondisi yang mungkin :
>>> A. Jika menggunakan randbetween, berarti tanggal ke-1 sampai tanggal
>>> ke-1000 langsung terbentuk bilangan acak dan bagian lain (kolom lain) pun
>>> harus bekerja simultan langsung mengolah bersamaan dari tanggal ke-1 sampai
>>> ke-1000. Artinya, yang paling memungkinkan adalah memasang formula dalam
>>> worksheet bukan menghitung formula dengan VBA.
>>>
>>> B. Jika yang dimaksud adalah tanggal ke-1 selesai disimulasi lalu pindah
>>> ke tanggal ke-2 lalu disimulasi sampai tanggal ke-1000,
>>> maka :
>>> 1. jika ada proses untuk menggunakan hasil sebuah cell yang sama untuk
>>> lebih dari satu proses simulasi.
>>> >> proses otomasinya menggunakan loop dari satu tanggal ke tanggal
>>> berikutnya.
>>> 2. jika tidak ada proses untuk menggunakan hasil sebuah cell yang sama
>>> untuk lebih dari satu proses simulasi
>>> >> proses otomasi bisa menggunakan VBA atau dengan formula dalam
>>> worksheet
>>>
>>> Kalo ndak salah kira-kira, jika kondisi A disusun dengan baik, mestinya
>>> proses membutuhkan waktu sekitar 30 sampai 350 detik saja untuk data kurang
>>> dari 30K. Jika kondisi B, maka proses VBA membutuhkan waktu sekitar 30
>>> sampai 350 detik juga pada data kurang dari 30K. Sedang untuk penggunaan
>>> formula di kondisi B.2., bisa tergantung jumlah formula dalam workbook yang
>>> butuh dikalkulasi Excel (antrian dalam proses kalkulasi Excel).
>>>
>>> Wassalam,
>>> Kid.
>>>
>>>
>>>
>>> 2014-09-30 20:47 GMT+10:00 lkm jktind [email protected]
>>> [belajar-excel] <[email protected]>:
>>>
>>>
>>>>
>>>> menggunakan data montecarlo
>>>>
>>>> 1. sebagian besar formula menempel di work sheet.
>>>> 2. semuanya mengunakan VBA -- --(mengunakan vlookup dan randbtween --
>>>> masing 3 pasang)
>>>>
>>>> dengan hasil
>>>> 1. 7000 detik -- cpu usage = 25 %
>>>> 2 .12.000 detik . ---> cpu useage = maksimal
>>>>
>>>> apakah bisa di artikan . formula di vba --- akan lebih lamban dari pada
>>>> di work sheet ?
>>>>
>>>>
>>>> Salam
>>>>
>>>> Lukman
>>>>
>>>>
>>>
>>
>
>