Jumat, 16 Januari 2015

Excel macro berbasis Barcode

Private Sub combro_kode_Change()
    Dim index As Integer
    Worksheets("REKAP").Activate
    Cells(combro_kode.ListIndex + 6, 4).Select
    text_nama = ActiveCell.Value
    Cells(combro_kode.ListIndex + 6, 5).Select
    text_satuan = ActiveCell.Value
    Cells(combro_kode.ListIndex + 6, 11).Select
    text_stock = ActiveCell.Value
    Worksheets("OUT").Activate
End Sub
Private Sub combro_user_Change()
    Dim index As Integer
 
    Worksheets("USER").Activate
    Cells(combro_user.ListIndex + 2, 2).Select
    text_user = ActiveCell.Value
    Cells(combro_user.ListIndex + 2, 3).Select
    text_dept = ActiveCell.Value
    Cells(combro_user.ListIndex + 2, 4).Select
    text_IO = ActiveCell.Value
    Worksheets("OUT").Activate
End Sub
Private Sub cmd_tambah_Click()
    Dim Wury As Long
    Wury = WorksheetFunction.CountA(Range("B:B")) + 4
    Cells(Wury, 2).Select
    Cells(Wury, 2).Value = combro_kode.Value
    Cells(Wury, 3).Value = text_nama.Value
    Cells(Wury, 4).Value = text_satuan.Value
    Cells(Wury, 15).Value = text_tanggal.Value
    Cells(Wury, 6).Value = text_jumlah.Value
    Cells(Wury, 7).Value = text_dept.Value
    Cells(Wury, 8).Value = text_user.Value
    Cells(Wury, 9).Value = text_IO.Value
    Cells(Wury, 10).Value = text_ket.Value
    Call bersih
    combro_kode.SetFocus
End Sub

     
Private Sub SpinButton1_Change()
    text_jumlah = SpinButton1.Value
End Sub

Sub bersih()
    combro_kode.Value = ""
    text_nama.Value = ""
    text_satuan.Value = ""
End Sub

Kamis, 15 Januari 2015

Excel macro berdasar nama barang

Private Sub cb_nama_barang_Change()
    Dim index As Integer
    Worksheets("REKAP").Activate
    Cells(cb_nama_barang.ListIndex + 6, 3).Select
    tb_Kode = ActiveCell.Value
    Cells(cb_nama_barang.ListIndex + 6, 5).Select
    tb_unit = ActiveCell.Value
    Cells(cb_nama_barang.ListIndex + 6, 11).Select
    text_stock = ActiveCell.Value
 
    Worksheets("OUT").Activate
End Sub

Private Sub cb_user_Change()
    Dim index As Integer
    Worksheets("USER").Activate
    Cells(cb_user.ListIndex + 2, 2).Select
    TextBox1 = ActiveCell.Value
    Cells(cb_user.ListIndex + 2, 3).Select
    TextBox2 = ActiveCell.Value
    Cells(cb_user.ListIndex + 2, 4).Select
    TextBox3 = ActiveCell.Value
    Worksheets("OUT").Activate
End Sub

Private Sub cmd_db_Click()
    Unload Me
    Worksheets("OUT").Activate
End Sub

Private Sub cmd_tambah_Click()
    Dim Wury As Long
    Wury = WorksheetFunction.CountA(Range("B:B")) + 4
    Cells(Wury, 2).Select
    Cells(Wury, 2).Value = tb_Kode.Value
    Cells(Wury, 3).Value = cb_nama_barang.Value
    Cells(Wury, 4).Value = tb_unit.Value
    Cells(Wury, 15).Value = tb_tgl_terima.Value
    Cells(Wury, 6).Value = tb_jumlah.Value
    Cells(Wury, 7).Value = TextBox2.Value
    Cells(Wury, 8).Value = TextBox1.Value
    Cells(Wury, 9).Value = TextBox3.Value
    Call bersih
    cb_nama_barang.SetFocus
End Sub

Private Sub SpinNilai_Change()
    tb_jumlah.Value = SpinNilai
End Sub

Sub bersih()
    tb_Kode.Value = ""
    cb_nama_barang.Value = ""
    tb_unit.Value = ""
 
End Sub

Private Sub tb_jumlah_Change()
On Error GoTo A
    tb_jumlah = Format(tb_jumlah * 1, "#,##0")
    Exit Sub
A:  tb_jumlah = ""
End Sub

Jumat, 29 Agustus 2014

Excel Mine for WH - Barang Keluar

Private Sub cb_nama_barang_Change()
    Dim index As Integer
    index = cb_nama_barang.ListIndex
    tb_kode = Cells(index + 1000, 29).Value
    tb_unit = Cells(index + 1000, 30).Value
End Sub
Private Sub cmd_data_base_Click()
    ThisWorkbook.Application.Visible = True
    Worksheets("OUT").Activate
    FormOut.Hide
End Sub

Private Sub cmd_tambah_data_Click()

    Dim Wury As Long
    Worksheets("OUT").Activate
    Wury = WorksheetFunction.CountA(Range("A:A")) + 3
    Cells(Wury, 1).Value = tb_kode.Value
    Cells(Wury, 2).Value = cb_nama_barang.Value
    Cells(Wury, 3).Value = tb_unit.Value
    Cells(Wury, 4).Value = tb_tgl_terima.Value
    Cells(Wury, 5).Value = tb_jumlah.Value
    Cells(Wury, 9).Value = tb_ket
'=============================================================================

Sorce Code VBA Excel

Credit untuk :belajar-vbe.blogspot.com/

Bermaksud untuk mengingat saja bukan untuk copy paste... mohon maaf credit di atas ya... sekalian belajar.

Beberapa Contoh Kode


AUTO RUN

Ada beberapa cara untuk membuat macros yang kita buat berjalan secara otomatis ketika pertama kali membukaworkbook. Yang pertama adalah Auto Open Method, yang diletakkan di modules, kedua adalah Workbook Open Method, yang diletakkan di pada obyek Workbook (lihat penjelasan pada langkah 3). Dua Contoh kode berikut akan menampilkan pesan “hi” ketika Workbook pertama kali dibuka.
Sub Auto_Open( )
Msgbox “hi”
End Sub
Private Sub Workbook_Open( )
Msgbox “hi”
End Sub