0% found this document useful (0 votes)
36 views4 pages

Coding Transaksi Kasirr

The document contains three VBA subroutines for managing data in an Excel workbook. The 'CmdTambah_Click' subroutine adds transaction data to the 'TRANSAKSI KASIR' sheet, 'PindahkanData' moves data from 'TRANSAKSI KASIR' to 'DATA TRANSAKSI', and 'Batal' clears the contents of a selected row in the 'TRANSAKSI KASIR' sheet. Each subroutine includes error handling and user notifications for successful operations or issues.

Uploaded by

setiaaqidah1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views4 pages

Coding Transaksi Kasirr

The document contains three VBA subroutines for managing data in an Excel workbook. The 'CmdTambah_Click' subroutine adds transaction data to the 'TRANSAKSI KASIR' sheet, 'PindahkanData' moves data from 'TRANSAKSI KASIR' to 'DATA TRANSAKSI', and 'Batal' clears the contents of a selected row in the 'TRANSAKSI KASIR' sheet. Each subroutine includes error handling and user notifications for successful operations or issues.

Uploaded by

setiaaqidah1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

TAMBAH

Private Sub CmdTambah_Click()

ActiveWorkbook.Sheets("TRANSAKSI KASIR").Activate

Sheets("TRANSAKSI KASIR").Range("C7").Select

Do

If IsEmpty(ActiveCell) = False Then

ActiveCell.Offset(1, 0).Select

End If

Loop Until IsEmpty(ActiveCell) = True

ActiveCell.Value = Sheets("TRANSAKSI KASIR").Range("L2").Value

ActiveCell.Offset(0, 1) = Sheets("TRANSAKSI KASIR").Range("L3").Value

ActiveCell.Offset(0, 2) = Sheets("TRANSAKSI KASIR").Range("L5").Value

ActiveCell.Offset(0, 3) = Sheets("TRANSAKSI KASIR").Range("L6").Value

ActiveCell.Offset(0, 4) = Sheets("TRANSAKSI KASIR").Range("L7").Value

ActiveCell.Offset(0, 5) = Sheets("TRANSAKSI KASIR").Range("L8").Value

ActiveCell.Offset(0, 6) = Sheets("TRANSAKSI KASIR").Range("L9").Value

Sheets("TRANSAKSI KASIR").Range("L5").ClearContents

Sheets("TRANSAKSI KASIR").Range("L8").ClearContents

Sheets("TRANSAKSI KASIR").Range("L5").Select

End Sub
SIMPAN DATA
DARI TRANSAKSI KASIR KE DATA TRANSAKSI

Sub PindahkanData()

Dim wsTransaksiKasir As Worksheet

Dim wsDataTransaksi As Worksheet

Dim lastRowKasir As Long

Dim lastRowData As Long

Dim dataRange As Range

Dim destRange As Range

' Set worksheets

Set wsTransaksiKasir = ThisWorkbook.Sheets("Transaksi Kasir")

Set wsDataTransaksi = ThisWorkbook.Sheets("Data Transaksi")

' Find the last row with data in Transaksi Kasir

lastRowKasir = wsTransaksiKasir.Cells(wsTransaksiKasir.Rows.Count, "C").End(xlUp).Row

' Check if there's data to copy

If lastRowKasir < 7 Then

MsgBox "Tidak ada data untuk dipindahkan.", vbExclamation

Exit Sub

End If

' Define the range to copy

Set dataRange = wsTransaksiKasir.Range("C7:I" & lastRowKasir)

' Find the last row with data in Data Transaksi

lastRowData = wsDataTransaksi.Cells(wsDataTransaksi.Rows.Count, "B").End(xlUp).Row

' If the last row is before row 3, set it to 2 (so data starts from row 3)

If lastRowData < 2 Then

lastRowData = 1

End If

' Define the destination range

Set destRange = wsDataTransaksi.Range("B" & lastRowData + 1)

' Copy data to destination range

dataRange.Copy

destRange.PasteSpecial xlPasteValues
' Clear the original data

dataRange.ClearContents

' Optional: Clear the clipboard

Application.CutCopyMode = False

MsgBox "Data berhasil dipindahkan.", vbInformation

End Sub
BATAL
Sub Batal()

Dim ws As Worksheet

Dim selectedRow As Long

' Set worksheet

Set ws = ThisWorkbook.Sheets("Transaksi Kasir")

' Check if a single cell is selected

If Selection.Cells.Count = 1 Then

' Get the selected row

selectedRow = Selection.Row

' Check if the selected row is within the range C7:I (starting from row 7)

If selectedRow >= 1 Then

' Clear the range C(selectedRow):I(selectedRow)

ws.Range("C" & selectedRow & ":I" & selectedRow).ClearContents

MsgBox "Data di baris " & selectedRow & " telah dikosongkan.",
vbInformation

Else

MsgBox "Baris yang dipilih berada di luar jangkauan yang diizinkan.",


vbExclamation

End If

Else

MsgBox "Silakan pilih satu sel dalam baris yang ingin Anda kosongkan.",
vbExclamation

End If

End Sub

You might also like