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

Code Inv

The document contains VBA code for Excel that defines several subroutines to manage order computations, clear orders, copy rows with quantities greater than zero, and save selections as PDF. It processes data from a specified range, calculates subtotals, taxes, and grand totals, and allows for saving the output as a PDF file in a designated directory. The code is structured to work with an active worksheet and includes user prompts for file saving confirmation.

Uploaded by

Kaith Lhorisse
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)
2 views4 pages

Code Inv

The document contains VBA code for Excel that defines several subroutines to manage order computations, clear orders, copy rows with quantities greater than zero, and save selections as PDF. It processes data from a specified range, calculates subtotals, taxes, and grand totals, and allows for saving the output as a PDF file in a designated directory. The code is structured to work with an active worksheet and includes user prompts for file saving confirmation.

Uploaded by

Kaith Lhorisse
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

Sub Compute_Order()

Dim ws As Worksheet

Dim rng As Range

Dim cellcount As Range

Dim destcell As Range

Dim i As Integer

Dim rownum As Integer

Dim itemcount As Integer

Dim csum As Range

rownum = 7

itemcount = 1

Set ws = ActiveSheet

Set rng = ws.Range("d7:d106")

For Each cellcount In rng

If cellcount.Value > 0 Then

Set destcell = ws.Cells(rownum, "L")

destcell.Value = itemcount

Set destcell = ws.Cells(rownum, "M")

destcell.Value = ws.Cells(cellcount.Row, "B").Value

Set destcell = ws.Cells(rownum, "N")

destcell.Value = ws.Cells(cellcount.Row, "C").Value

Set destcell = ws.Cells(rownum, "O")

destcell.Value = ws.Cells(cellcount.Row, "D").Value

Set destcell = ws.Cells(rownum, "P")

destcell.Value = ws.Cells(cellcount.Row, "E").Value

Set destcell = ws.Cells(rownum, "Q")


destcell.Value = ws.Cells(rownum, "o").Value * ws.Cells(rownum, "p").Value

rownum = rownum + 1

itemcount = itemcount + 1

End If

Next cellcount

Set destcell = Range("p7").End(xlDown).Offset(1, 0)

destcell.Value = "Sub total"

Set rng = Range("q7:q" & Range("q7").End(xlDown).Row)

Set csum = Range("q7").End(xlDown).Offset(1, 0)

csum.Formula = "=SUM(" & rng.Address(False, False) & ")"

Set destcell = Range("p7").End(xlDown).Offset(1, 0)

destcell.Value = "Tax 12%"

Set csum = Range("q7").End(xlDown).Offset(1, 0)

csum.Formula = csum.Offset(-1, 0).Value * 0.12

Set destcell = Range("p7").End(xlDown).Offset(1, 0)

destcell.Value = "Grand Total"

Set csum = Range("q7").End(xlDown).Offset(1, 0)

csum.Formula = csum.Offset(-2, 0).Value + csum.Offset(-1, 0).Value

End Sub

Sub clearorder()

Dim ws As Worksheet

Dim rng As Range


Set ws = ActiveSheet

Set rng = ws.Range("d7:d106")

rng.Value = 0

Set rng = ws.Range("l7:q" & Range("q7").End(xlDown).Row)

rng.Value = " "

End Sub

Sub copyrowsofqtyisgreaterthanzero()

Dim ws As Worksheet

Dim qtyrange As Range

Dim cell As Range

Dim destcell As Range

Dim rownum As Integer

Set ws = ActiveSheet

Set qtyrange = ws.Range("d7:d10")

rownum = 7

For Each cell In qtyrange

If IsNumeric(cell.Value) And cell.Value > 0 Then

Set destcell = ws.Cells(rownum, "L")

ws.Rows(cell.Row).Copy Destination:=destcell

rownum = rownum + 1

End If

Next cell

End Sub
Sub SaveSelectionAsPDF()

Dim Filepath As String

Dim FileName As String

Dim FullPath As String

Dim CurrentDateTime As String

Dim SelectionRange As Range

Range("L2:Q" & Range("q7").End(xlDown).Row).Select

' Set the selected range

Set SelectionRange = Selection

'Set the desired file path (change this to your preferred directory)

Filepath = "C:\Users\Kaith Lhorisse\OneDrive\Documents\Desktop\AIS GALVEZ\"

'Get the current and time

CurrentDateTime = Format(Now, "yyyy-mm-dd_hh-mm-ss")

'Create the file name

FileName = "receipt_" & CurrentDateTime & ".pdf"

'combine the path and file name

FullPath = Filepath & FileName

'Save the swelected range as pdf

SelectionRange.ExportAsFixedFormat Type:=xlTypePDF, FileName:=FullPath, Quality:=xlQualityStandard, _

IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:=True

'Inform the user

MsgBox "Receipt saved to " & FullPath

End Sub

You might also like