Hi,
I have a userform with many controls, and below are some of them
The above are the main controls that I need in this inquiry
ex: If the BarCode is "101" and I need to add this item to 4 clients, then
I have this piece of code in "cmdAdd" to insert the above data to sheet16
What I need is:
With the above code, if the all the clients names don't exist in sheet16, then the code will run as I need
Else if all the names are exist with BarCode "101" or any other BarCode, then the code will run as I need
But ex: if I need to insert BarCode "101" and these names: (Client A, Client B, Client E, Client F) then
Please help me fixing my code
I'm not sure if I explained what I need well, but if you need any more details please let me know
Many thanks in advanced
I have a userform with many controls, and below are some of them
- txtBarCode (TextBox) [where I insert the needed Item's Barcode]
- cmbNum (ComboBox) [(List from 1 to 8) to Identify the clients number]
- txt_Name1, txt_Name2 ...txt_Name8 (TextBox) [To insert the client names, (if cmbNum = 3 then I should insert 3 names...)]
- cmdAdd (CommandButton) [to add the inserted values to sheet16]
The above are the main controls that I need in this inquiry
ex: If the BarCode is "101" and I need to add this item to 4 clients, then
- txtBarCode = 101
- cmbNum = 4
- txt_Name1 = Client A
- txt_Name2 = Client B
- txt_Name3 = Client C
- txt_Name4 = Client D
I have this piece of code in "cmdAdd" to insert the above data to sheet16
Code:
Dim fcell As Range
With ws
For i = 1 To cmbNum.Value
Set c = .Range("I:I").Find(What:=Me.Controls("txt_Name" & i), LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If Not c Is Nothing Then
Set fcell = c
Do
If .Range("C" & c.Row) = BarCode And .Range("I" & c.Row) = Me.Controls("txt_Name" & i) Then
.Range("F" & c.Row) = .Range("F" & c.Row) + Me.txtQty
End If
Set c = .Range("I:I").FindNext(c)
'exit find loop if find jumped to the top again
Loop While fcell.Address <> c.Address
Else
GoTo new_item
End If
Next i
GoTo finish
What I need is:
- Check if the name is exist and has the same BarCode, then just add 1 to the quantity
- Else, GoTo new_item
- Then check the second name...
With the above code, if the all the clients names don't exist in sheet16, then the code will run as I need
Else if all the names are exist with BarCode "101" or any other BarCode, then the code will run as I need
But ex: if I need to insert BarCode "101" and these names: (Client A, Client B, Client E, Client F) then
- The quantity for Client A & Client B will be +1 and the same data for these 2 names will be added as new row(while I just need to add the quantity)
- Client E & Client F will be added as new row (as I need)
Please help me fixing my code
I'm not sure if I explained what I need well, but if you need any more details please let me know
Many thanks in advanced