my show data error in ()

Bryanlim

New Member
Joined
Jul 5, 2020
Messages
6
Office Version
  1. 2010
Platform
  1. Windows
VBA Code:
Private Sub Add_button_Product_Click()
'''''''''''''Validation'''''''''''''
If Me.txt_ProductDescription.Value = "" Then
MsgBox "Please Enter Product Name", vbCritical
Exit Sub

End If
If IsNumeric(Me.txt_QTY) = False Then
MsgBox "Please Enter The Correct QTY", vbCritical
Exit Sub
End If

If IsNumeric(Me.Txt_UnitCost) = False Then
MsgBox "Please Enter The Correct Unit Cost Price", vbCritical
Exit Sub

End If
If IsNumeric(Me.txt_RetailPrice) = False Then
MsgBox "Please Enter The Correct Retail Price", vbCritical
Exit Sub

End If
If IsNumeric(Me.txt_UnitCost_CS) = False Then
MsgBox "Please Enter The Correct Unit Cost per Case", vbCritical
Exit Sub
End If


If IsNumeric(Me.txt_WSPrice_CS) = False Then
MsgBox "Please Enter The Correct Wholesale Price per case", vbCritical
Exit Sub
End If

If IsNumeric(Me.Txt_Frieght) = False Then
MsgBox "Please Enter The Correct Frieght", vbCritical
Exit Sub
End If



''''''' Check Duplicate
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Master List")
If Application.WorksheetFunction.CountIf(sh.Range("B:B"), Me.txt_ProductDescription.Value) > 0 Then
MsgBox "This Product is already available in Master List", vbCritical
Exit Sub
End If

'''''''''''''''''' Add Data
Dim Lr As Integer
Lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))

sh.Range("A" & Lr + 1).Value = Lr
sh.Range("B" & Lr + 1).Value = Me.Txt_stocknumber.Value
sh.Range("d" & Lr + 1).Value = Me.Txt_packing.Value
sh.Range("e" & Lr + 1).Value = Me.txt_QTY.Value
sh.Range("f" & Lr + 1).Value = Me.Txt_Unit.Value
sh.Range("g" & Lr + 1).Value = Me.Txt_UnitCost.Value
sh.Range("h" & Lr + 1).Value = Me.txt_UnitCost_CS.Value
sh.Range("i" & Lr + 1).Value = Me.txt_RetailPrice.Value
sh.Range("j" & Lr + 1).Value = Me.txt_WSPrice_CS.Value
sh.Range("k" & Lr + 1).Value = Me.Txt_Frieght.Value
sh.Range("l" & Lr + 1).Value = Me.txt_Percentage.Value

''''''''''''' Clear Boxes
Me.Txt_stocknumber.Value = ""
Me.Txt_packing.Value = ""
Me.txt_QTY.Value = ""
Me.Txt_Unit.Value = ""
Me.Txt_UnitCost.Value = ""
Me.txt_UnitCost_CS.Value = ""
Me.txt_RetailPrice.Value = ""
Me.txt_WSPrice_CS.Value = ""
Me.Txt_Frieght.Value = ""
Me.txt_Percentage.Value = ""

Call show_data

MsgBox "Product has beed added in Master List", vbInformation

End Sub

Sub show_data()
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Master List")
Dim Lr As Integer
Lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))

If Lr = 1 Then Lr = 2

With Me.ListBox1
    .ColumnCount = 13
    .ColumnHeads = True
    .ColumnWidths = "60,200,100,0,150,50,50,100,100,100,100,20,10"
    .RowSource = "Master List!A2:M" & Lr
   
End With
   


End Sub


Private Sub UserForm_Activate()
Call show_data

End Sub

M trying to create this vba.. but in my show data () in .rowsource shows debug and error pls help.. and can you help me also for multiple products encoding? thanks
 

Attachments

  • show data.jpg
    show data.jpg
    116.5 KB · Views: 7

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
try this update to your code & see if resolves your issue

VBA Code:
Sub show_data()
    Dim sh As Worksheet
    Dim Lr As Long
    
    Set sh = ThisWorkbook.Sheets("Master List")
    
    Lr = Application.WorksheetFunction.CountA(sh.Range("A:A"))
    
    If Lr = 1 Then Lr = 2
    
    With Me.ListBox1
        .ColumnCount = 13
        .ColumnHeads = True
        .ColumnWidths = "60,200,100,0,150,50,50,100,100,100,100,20,10"
        .RowSource = "'" & sh.Name & "'!A2:M" & Lr
    End With

End Sub

Dave
 
Upvote 0
thank you very much dave... it works like charm... do you have any idea how the multiple entry works? like... if i click the vba.. it will just go in the excel sheet right away
 
Upvote 0
thank you very much dave... it works like charm... do you have any idea how the multiple entry works? like... if i click the vba.. it will just go in the excel sheet right away

are you referring to your Add_button_Product_Click code & if so, what is the issue you are having?

Dave
 
Upvote 0
i have a blank pink command button, in left side... because the vba i created can be input items only 1 at the time... so... is there a code that can do multiple items at a time? like.. if i click the pink vba... it will bring me to the excel form... then input many items as posible
 
Upvote 0
I guess what you want probably doable but not something I have tried in past - maybe another here can assist with this part of your question

Dave
 
Upvote 0

Forum statistics

Threads
1,214,653
Messages
6,120,750
Members
448,989
Latest member
mariah3

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