PDA

View Full Version : pleace help me sort my table.



stramvaier
08-09-2011, 01:23 AM
im very new to VBA. i have now searched the forum for 2 weeks, tried many many codes, manipulated and extracted and it gets me nowhere. im stuck.... any help is appreciated as im soon to melt my brain. i cannot find my way around a working code for this problem.

in the attached workbook there is a table that displays different sizes of parts.

when i start to sort my table i want to look first in row 4 of my table.
Then look in my table if any other row contain the same value in cell A and B(not a or b,but a and b together). If any other row have the same value in A and B, i want to delete the duplicate rows and add theyr quantity from cell C to the first rows cell C.

i want to delete the rows that has the same value as my first checked cells and add the quantity in colum C to the C column of the first row so that i am left with only one row containing the info in A,B and C with the correct ammount in C

then move to the next row in my table and do the same until all the rows are sorted.

maybe there isnt a quick solution to this but if anyone can help im very happy.:help

bjoshi
08-09-2011, 01:50 AM
Here's the code you need.


Sub sortt()
Range("A4").Select
If Range("A5") <> "" Then
Selection.End(xlDown).Select
End If
xrow = ActiveCell.Row
Range("A4").Select
For i = 1 To xrow
If ActiveCell.Value <> "" Then
A = ActiveCell.Value
B = ActiveCell.Offset(0, 1).Value
C = ActiveCell.Offset(0, 2).Value
For j = 1 To xrow
If ActiveCell.Offset(j, 0).Value = A Then
If ActiveCell.Offset(j, 1).Value = B Then
C = C + ActiveCell.Offset(j, 2).Value
ActiveCell.Offset(0, 2).Value = C
ActiveCell.Offset(j, 0).EntireRow.Delete
j = j - 1
End If
End If
Next j
ActiveCell.Offset(1, 0).Select
End If
Next i
End Sub