mismatch this code for add items to listbox in userfrom

MohamedAmin

New Member
Joined
May 17, 2023
Messages
21
Office Version
  1. 2021
Platform
  1. Windows
VBA Code:
Private Sub CmdAddItem_Click() 'add item
ThisWorkbook.Activate
'====check product list =====
If Me.CbProductList.MatchFound = False Then: MsgBox "Data Error : Please select of items list ", vbCritical, "Inventory Program ": Me.CbProductList.SetFocus: Exit Sub

'===== check q as number====
If Not IsNumeric(Me.TbQuantity.Value) Then: MsgBox "Data Error: not have quantity: Please enter the quantity ", vbCritical, "Inventory Program": Me.TbQuantity.SetFocus: Exit Sub

'====== check raseed =======
If Not Me.CbInvStore.Value = Data.Range("BF7") Then GoTo 11
If Val(Me.TbQuantity.Value) + Val(Me.TbShipQuantity.Value) > Val(Me.TbRaseedNow.Value) Then
confir = MsgBox(" Quantity available is not sufficient warehouse for sale. please check inventory " & vbCrLf & "Do you want to continue ?", _
vbYesNo + vbMsgBoxLeft, "Inventory Programs ")
If confir = vbNo Then: Me.TbQuantity.Value = "": Me.TbQuantity.SetFocus: Exit Sub
End If
'===========================

11 np = Val(Me.TbNetPrice.Value) * Val(Me.TbQuantity.Value) * (Val(Me.TbMohDiscount.Value) / 100)

'On Error Resume Next
With ListBox1
Dim i As Integer
Dim b
i = .ListCount
.AddItem i
.List(i, 0) = Me.TbCode.Value
.List(i, 1) = Me.CbProductList.Value
.List(i, 2) = Me.TbProductType.Value
.List(i, 3) = Me.TbQuantity.Value
.List(i, 4) = Format(Me.TbNetPrice.Value, "0.00")
.List(i, 5) = Val(Me.TbQuantity.Value) * Val(Me.TbNetPrice.Value)
.List(i, 7) = Val(Me.TbQuantity.Value) * Val(Me.TbShipQuantity.Value)
.List(i, 8) = Me.TbProductPrice.Value

If Me.CbInvStore = "Purchase" Then
.List(i, 8) = Val(Me.TbNetPrice.Value) + Val(Me.TbShipQuantity.Value)
End If

If Not IsNumeric(Me.TbMohDiscount.Value) Then GoTo 1
.List(i, 6) = Format(Me.TbMohDiscount.Value / 100, "0.00%")

'b = 1 + (Me.TbMohDiscount / 100)

1 If b <= 0 Or b = Empty Then
.List(i, 9) = np
Else
.List(i, 9) = np / b
End If

.List(i, 9) = Val(.List(i, 5)) - np + Val(.List(i, 7))

If Me.CbInvStore = "Sales" Then
.List(i, 10) = Me.TbProductPrice.Value * Me.TbQuantity.Value (Here is the Mismatch )
.List(i, 11) = Val(.List(i, 9)) - np - Val(.List(i, 10))
End If

.List(i, 4) = Format(.List(i, 4), "$#,##0.00")
.List(i, 5) = Format(.List(i, 5), "$#,##0.00")
.List(i, 7) = Format(.List(i, 7), "$#,##0.00")
.List(i, 8) = Format(.List(i, 8), "$#,##0.00")
.List(i, 9) = Format(.List(i, 9), "$#,##0.00") 'net price
.List(i, 10) = Format(.List(i, 10), "$#,##0.00")
.List(i, 11) = Format(.List(i, 11), "$#,##0.00")

'.List(i, 10) = Val(.List(i, 3)) * Val(.List(i, 9)) 'q only * net price = total net price
'.List(i, 11) = Val(.List(i, 8)) * Val(Me.TbNetPrice.Value) 'all q+b * net price = total puplic price
'.List(i, 10) = Format(.List(i, 10), "#,##0.00")
'.List(i, 11) = Format(.List(i, 11), "#,##0.00")
.Selected(1) = True
End With

'For Total
Dim sum As Double
For Row = 1 To ListBox1.ListCount - 1
sum = sum + ListBox1.List(Row, 9) (Here is the Mismatch )
Next Row
Me.TbTotalNetPrice = sum
Me.TbTotalNetPrice = Format(Me.TbTotalNetPrice, "$#,##0.00")

'For Cost
If Me.CbInvStore = "Sales" Then
Dim sumc As Double
For Row = 1 To ListBox1.ListCount - 1
sumc = sumc + ListBox1.List(Row, 10) (Here is the Mismatch )
Next Row
Me.TbInvoCost = sumc
Me.TbInvoCost = Format(Me.TbInvoCost, "$#,##0.00")

'For Profit
Dim sump As Double
For Row = 1 To ListBox1.ListCount - 1
sump = sump + ListBox1.List(Row, 11) (Here is the Mismatch )
Next Row
Me.TbProfit = sump
Me.TbProfit = Format(Me.TbProfit, "$#,##0.00")
Me.TbProfit = Format(sum - sumc, "$#,##0.00")

End If
Me.TbCode = ""
Me.TbQuantity = ""
Me.TbBonusNet = ""
Me.TbBonusPercent = ""

Set TotalS = Profit.Range("Q8")
Me.TotalSales = Format(TotalS.Value + Me.TbTotalNetPrice.Value, "$#,##0.00")

Set Totalc = Profit.Range("R8")
Me.TotalCost = Format(Totalc.Value + Me.TbInvoCost.Value, "$#,##0.00")

Set Totalp = Profit.Range("S8")
Me.TotalProfit = Format(Totalp.Value + Me.TbProfit.Value, "$#,##0.00")

Me.LbPercentage.Value = Format(TotalProfit.Value / TotalSales.Value, "0.00%")


Me.TbCode.SetFocus


End Sub
 
Last edited by a moderator:
What do you mean "When running"? The code is only meant to run once you encounter an error - what line did the error occur on?
HAs the code changed at all from what you originally posted?
 
Upvote 0

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
What do you mean "When running"? The code is only meant to run once you encounter an error - what line did the error occur on?
HAs the code changed at all from what you originally posted?
I found the problem is the textbox continues with "$#,##0.00" $ that why cant multiplication
 
Upvote 0

Forum statistics

Threads
1,214,950
Messages
6,122,436
Members
449,083
Latest member
Ava19

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top