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
[TABLE="width: 320"]
<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl64, width: 64"][/TD]
[TD="class: xl64, width: 64"]A[/TD]
[TD="class: xl64, width: 64"]B[/TD]
[TD="class: xl64, width: 64"]C[/TD]
[TD="class: xl64, width: 64"]D[/TD]
[/TR]
[TR]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]Num[/TD]
[TD="class: xl64"]BarCode[/TD]
[TD="class: xl64"]Qty[/TD]
[TD="class: xl64"]Name[/TD]
[/TR]
[TR]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]102[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]103[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientB[/TD]
[/TR]
[TR]
[TD="class: xl64"]6[/TD]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientC[/TD]
[/TR]
[TR]
[TD="class: xl64"]7[/TD]
[TD="class: xl64"]6[/TD]
[TD="class: xl64"]103[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientC[/TD]
[/TR]
</tbody>[/TABLE]
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
[TABLE="width: 320"]
<colgroup><col width="64" span="5" style="width:48pt"> </colgroup><tbody>[TR]
[TD="class: xl64, width: 64"][/TD]
[TD="class: xl64, width: 64"]A[/TD]
[TD="class: xl64, width: 64"]B[/TD]
[TD="class: xl64, width: 64"]C[/TD]
[TD="class: xl64, width: 64"]D[/TD]
[/TR]
[TR]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]Num[/TD]
[TD="class: xl64"]BarCode[/TD]
[TD="class: xl64"]Qty[/TD]
[TD="class: xl64"]Name[/TD]
[/TR]
[TR]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]2[/TD]
[TD="class: xl64"]102[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]3[/TD]
[TD="class: xl64"]103[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientA[/TD]
[/TR]
[TR]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]4[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientB[/TD]
[/TR]
[TR]
[TD="class: xl64"]6[/TD]
[TD="class: xl64"]5[/TD]
[TD="class: xl64"]101[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientC[/TD]
[/TR]
[TR]
[TD="class: xl64"]7[/TD]
[TD="class: xl64"]6[/TD]
[TD="class: xl64"]103[/TD]
[TD="class: xl64"]1[/TD]
[TD="class: xl64"]ClientC[/TD]
[/TR]
</tbody>[/TABLE]