![]() |
Sum values based on criteria in another column
Essentially, what I am looking to do is go through a sheet and say:
If value of C3 matches value of C2, then add J2+J3, and then delete row 3. If i was familiar with excel, or knew how to script/program in excel, i would think it would be something like this (basic idea...) n == 3 DO While (n < Number_of_rows) DO While (Cn == C2) J2 == J2 + Jn Delete Row 3 End Do n == n+1 END DO ^^ That would be check to see if the contents of column C matched the contents of C2, and if they did, would sum the J column values in J2. I would then have more code to check to see if any of the values of column C matched the new value in C3, and would combine all J column values into J3. Then check C4 and sum into J4, C5 sum J's into J5... Etc. All the way through C(number of rows) into J(number of rows) It's been a while since I did any real programming, and the only language i even know is fortran, so sorry if that code is hard to follow... Any help would be very much appreciated!!! |
Sum values based on criteria in another column
Okay, and now since I am a little slow, and haven't done much of anything in
excel, is there a good resource to actually learning how to implement that bit of code into excel? I don't know really how to begin writing a program/script for excel :-/ "Don Guillett" wrote: Should do it Sub Addupifmatch() For i = Cells(Rows.Count, "c").End(xlUp).Row To 3 Step -1 If Cells(i, "c") = Range("c2") Then mc = mc + Cells(i, "J") Rows(i).Delete End If Next MsgBox mc End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "Derek Johansen" <Derek wrote in message ... Essentially, what I am looking to do is go through a sheet and say: If value of C3 matches value of C2, then add J2+J3, and then delete row 3. If i was familiar with excel, or knew how to script/program in excel, i would think it would be something like this (basic idea...) n == 3 DO While (n < Number_of_rows) DO While (Cn == C2) J2 == J2 + Jn Delete Row 3 End Do n == n+1 END DO ^^ That would be check to see if the contents of column C matched the contents of C2, and if they did, would sum the J column values in J2. I would then have more code to check to see if any of the values of column C matched the new value in C3, and would combine all J column values into J3. Then check C4 and sum into J4, C5 sum J's into J5... Etc. All the way through C(number of rows) into J(number of rows) It's been a while since I did any real programming, and the only language i even know is fortran, so sorry if that code is hard to follow... Any help would be very much appreciated!!! |
Sum values based on criteria in another column
Okay, i figured out where to implement the VBA Script, but now my question is
What does the line mc = mc + cells(i, "J") do? Also, how difficult would it be to implement this for every row? What i mean is: After it checks all the values against Cell C2 and sums the total, it then checks the remaining values against C3, and then against C4, etc... "Derek Johansen" wrote: Okay, and now since I am a little slow, and haven't done much of anything in excel, is there a good resource to actually learning how to implement that bit of code into excel? I don't know really how to begin writing a program/script for excel :-/ "Don Guillett" wrote: Should do it Sub Addupifmatch() For i = Cells(Rows.Count, "c").End(xlUp).Row To 3 Step -1 If Cells(i, "c") = Range("c2") Then mc = mc + Cells(i, "J") Rows(i).Delete End If Next MsgBox mc End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "Derek Johansen" <Derek wrote in message ... Essentially, what I am looking to do is go through a sheet and say: If value of C3 matches value of C2, then add J2+J3, and then delete row 3. If i was familiar with excel, or knew how to script/program in excel, i would think it would be something like this (basic idea...) n == 3 DO While (n < Number_of_rows) DO While (Cn == C2) J2 == J2 + Jn Delete Row 3 End Do n == n+1 END DO ^^ That would be check to see if the contents of column C matched the contents of C2, and if they did, would sum the J column values in J2. I would then have more code to check to see if any of the values of column C matched the new value in C3, and would combine all J column values into J3. Then check C4 and sum into J4, C5 sum J's into J5... Etc. All the way through C(number of rows) into J(number of rows) It's been a while since I did any real programming, and the only language i even know is fortran, so sorry if that code is hard to follow... Any help would be very much appreciated!!! |
Sum values based on criteria in another column
I can't seem to visualize what you really want so, if desired, send your file to my address below along with a clear explanation and before/after examples. Also, include a snippet of this msg. -- Don Guillett Microsoft MVP Excel SalesAid Software "Derek Johansen" wrote in message ... Okay, i figured out where to implement the VBA Script, but now my question is What does the line mc = mc + cells(i, "J") do? Also, how difficult would it be to implement this for every row? What i mean is: After it checks all the values against Cell C2 and sums the total, it then checks the remaining values against C3, and then against C4, etc... "Derek Johansen" wrote: Okay, and now since I am a little slow, and haven't done much of anything in excel, is there a good resource to actually learning how to implement that bit of code into excel? I don't know really how to begin writing a program/script for excel :-/ "Don Guillett" wrote: Should do it Sub Addupifmatch() For i = Cells(Rows.Count, "c").End(xlUp).Row To 3 Step -1 If Cells(i, "c") = Range("c2") Then mc = mc + Cells(i, "J") Rows(i).Delete End If Next MsgBox mc End Sub -- Don Guillett Microsoft MVP Excel SalesAid Software "Derek Johansen" <Derek wrote in message ... Essentially, what I am looking to do is go through a sheet and say: If value of C3 matches value of C2, then add J2+J3, and then delete row 3. If i was familiar with excel, or knew how to script/program in excel, i would think it would be something like this (basic idea...) n == 3 DO While (n < Number_of_rows) DO While (Cn == C2) J2 == J2 + Jn Delete Row 3 End Do n == n+1 END DO ^^ That would be check to see if the contents of column C matched the contents of C2, and if they did, would sum the J column values in J2. I would then have more code to check to see if any of the values of column C matched the new value in C3, and would combine all J column values into J3. Then check C4 and sum into J4, C5 sum J's into J5... Etc. All the way through C(number of rows) into J(number of rows) It's been a while since I did any real programming, and the only language i even know is fortran, so sorry if that code is hard to follow... Any help would be very much appreciated!!! |
All times are GMT +1. The time now is 07:18 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com