Hi,
I have a code that works fine with all conditions accept the one and need your help please
My code says:
With my code below, I have 2 parts work fine unless second part
ex: If I need to add new data (BarCode= 103, Qty= 1, Name = ClientA)
Then, Cell "C4" should be 2
But I don't have the code to find Cell "C4" and add the quantity
Please help me getting this done and many thanks in advanced
<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>
</tbody>
I have a code that works fine with all conditions accept the one and need your help please
My code says:
- Check if the name is exist or not
- If not, then GoTo new_item (it works great)
- If exist and the BarCode is exist for the same name then just add the quantity (This is what I need)
- If exist and the BarCode is not exist for the same name then GoTo new_item (it works great)
With my code below, I have 2 parts work fine unless second part
ex: If I need to add new data (BarCode= 103, Qty= 1, Name = ClientA)
Then, Cell "C4" should be 2
But I don't have the code to find Cell "C4" and add the quantity
Please help me getting this done and many thanks in advanced
Code:
Set c = ws.Range("D:D").Find(what:=txt_Name, LookIn:=xlValues, lookat:=xlWhole, MatchCase:=False)
If c Is Nothing Then
GoTo new_item
ElseIf Not c Is Nothing And Application.WorksheetFunction.CountIfs(ws.Range("B:B"), Me.BarCode, ws.Range("D:D"), Me.txt_Name) = 1 Then
ws.Range("C" & c.Row) = ws.Range("C" & c.Row) + Me.txtQty
ElseIf Not c Is Nothing And Application.WorksheetFunction.CountIfs(ws.Range("B:B"), Me.BarCode, ws.Range("D:D"), Me.txt_Name) = 0 Then
GoTo new_item
A | B | C | D | |
1 | Num | BarCode | Qty | Name |
2 | 1 | 101 | 1 | ClientA |
3 | 2 | 102 | 1 | ClientA |
4 | 3 | 103 | 1 | ClientA |
5 | 4 | 101 | 1 | ClientB |
6 | 5 | 101 | 1 | ClientC |
7 | 6 | 103 | 1 | ClientC |
<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>
</tbody>