Faiz Abdat
New Member
- Joined
- Sep 13, 2017
- Messages
- 3
Hi everyone,
I'm working now with a userform in VBA, in which i can input a data using that form to other sheet
here's the code that i used, the last code won't work as I wish,
the column "N" should total column "K", "L", and "M" in each row..
but i didn't work that way,
if anyone knows on what part that code is incorrect, please let me know
really appreciate you help
thank you
I'm working now with a userform in VBA, in which i can input a data using that form to other sheet
here's the code that i used, the last code won't work as I wish,
the column "N" should total column "K", "L", and "M" in each row..
but i didn't work that way,
if anyone knows on what part that code is incorrect, please let me know
really appreciate you help
thank you
Code:
Private Sub postrecord_Click()
' find the next row on the data sheet
Dim Nextrow, sumrow As String
Nextrow = Worksheets("Invoice").Cells(Rows.Count, "A").End(xlUp).Row + 1
sumrow = Worksheets("Invoice").Cells(Rows.Count, "K").End(xlUp)
Dim salesAmt, vat, wht As Double
salesAmt = Cells(sumrow - 1, "K")
vat = Cells(sumrow - 1, "L")
wht = Cells(sumrow - 1, "M")
'Write the values from this form to that row
With Worksheets("Invoice")
'enter date and time stamp in record
With .Cells(Nextrow, "A")
.Value = Now
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
.Cells(Nextrow, "B").Value = Application.UserName 'enter user name in column B
.Cells(Nextrow, "C").Value = Me.Cb_companyname 'company name
.Cells(Nextrow, "D").Value = Me.tb_Invoicenumber 'invoice number
With .Cells(Nextrow, "E")
.Value = Me.Cb_salesperiod.Text 'year of sales
.NumberFormat = ("###")
End With
.Cells(Nextrow, "F").Value = Me.tb_invreceived 'month of sales
If Me.ob_fob = True Then 'FOB??
.Cells(Nextrow, "G").Value = "FOB"
Else
.Cells(Nextrow, "G").Value = ""
End If
If Me.ob_cif = True Then 'CIF??
.Cells(Nextrow, "G").Value = "CIF"
Else
.Cells(Nextrow, "G").Value = ""
End If
.Cells(Nextrow, "H").Value = Me.Cb_salesproduct 'CPO, PK or FFB??
With .Cells(Nextrow, "I")
.Value = Me.tb_qty.Text
.NumberFormat = "#,###0.0"
End With
With .Cells(Nextrow, "J")
.Value = Me.tb_price.Text
.NumberFormat = "#,###0.0"
End With
With .Cells(Nextrow, "K") 'Sales Amount
.Value = Val(tb_qty.Text) * Val(tb_price.Text)
.NumberFormat = "#,###0.0"
End With
If Me.Cb_VAT = True Then 'add VAT 10%??
.Cells(Nextrow, "L").Value = Val(tb_qty.Text) * Val(tb_price.Text) * 0.1
Else
.Cells(Nextrow, "L").Value = 0
End If
If Me.Cb_WHT = True Then 'add WHT 0.25%??
.Cells(Nextrow, "M").Value = Val(tb_qty.Text) * Val(tb_price.Text) * -0.0025
Else
.Cells(Nextrow, "M").Value = 0
End If
.Cells(Nextrow, "N").Value = (salesAmt + vat + wht) 'Total Invoice Amount
End With
'Unload the form
Unload Me
Last edited by a moderator: