PDA

View Full Version : Solved: automate =sum for two lines



nickxx4360
10-10-2008, 01:03 PM
Hello,
I am new to coding so please forgive the ignorance on the subject.

I have to do a project for my company and part of it has to do with editing a excel spread sheet then saving it. I need to automate it so I used the macro recorder to do one have of what I need to do. The other half of what I need to do is where I get stuck.

Attached is the spreadsheet.

First I need to delete A1:A9. I get that done fine by recording a macro. After I delete those lines I then have to get the sum for C12 and C13. notice they are have the same trade ID (oxy) after I get the sum I need to delete either one (oxy) and leave the sum in place so I ned up with one entry for oxy.


I will attach two spreadsheets, one before and one after the edit.

Thanks for the help in advance.

Nick ?The computer guy?

nickxx4360
10-10-2008, 01:04 PM
after edit

Bob Phillips
10-10-2008, 01:10 PM
Sub ClearUp()
Dim LastRow As Long
Dim i As Long

With ActiveSheet

LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For i = LastRow To 10 Step -1

If .Cells(i, "A").Value = .Cells(i - 1, "A").Value Then

.Cells(i - 1, "C").Value = .Cells(i - 1, "C").Value + _
.Cells(i, "C").Value
.Rows(i).Delete
End If
Next i

.Rows("1:9").Delete
End With
End Sub

nickxx4360
10-10-2008, 05:41 PM
Thanks I will give it a try.

nickxx4360
10-10-2008, 05:56 PM
OMG. Thanks It worked.

If anyone can recommend a good book and some courses to start with, that would be great.

This code is way over my head.

I feel like I cheated and I would love to explain for the most part what the lines mean.

Thanks soo much.

Nick “the Computer guy"