add new row with formula...some problem with macro
hi,
i've got some problem with my macro. I need to sum up values from column d based on value from column A, and than to the same thing i column E. It's hard for me to explain this but when you see att file i think that everything will be clear. In sheet1 you can see how it looks now, and in sheet2 how it's supose to be. I've got some macro, so it might be helpful.
I don't know how to wirite that i want excel to add new row before new value apear in column A, and sum up values from column D and E.
And is it possible to add boarders like i do that in sheet2?
I hope printscreem will be helpful
If someone can help me it will be great, or give me some example, clue how can i do that.
Thank you in advance
ps. I need to add that i have no idea how many values I will have in column A (usually it's something about 300) and how many rows I'll have betwen them (more less 10-50, hard to say)
PHP Code:
Sub s_umA() 'sum up values from column 5(E) and put results to coolumn 8 (h) suma = 0 rowa = 2 For i = 2 To Cells(Rows.Count, 5).End(xlUp).Row + 1 If Cells(i, 1) <> "" Then Cells(rowa, 8).Value = suma suma = Cells(i, 5) rowa = i Else suma = suma + Cells(i, 5) End If Next i Cells(rowa, 8).Value = suma End Sub
Re: add new row with formula...some problem with macro
Yes. it's work great, I made some chages, but you made my day
And is it possible to automaticlly add boarderslike you can see in sheet2 or printscreen?
PHP Code:
Sub SumTotalx() Dim LR As Long, i As Long Dim x As Long, y As Long
With ActiveSheet LR = .Cells(Rows.Count, 1).End(xlUp).Row y = LR + 1 For i = LR To 2 Step -1 If Len(Trim(.Cells(i, 1).Value)) > 0 Then ' Do .Rows(y).Insert .Cells(y, 4).Value = WorksheetFunction.Sum(Range("D" & i & ":D" & y - 1)) .Cells(y, 1).Value = "Sum of " & .Cells(i, 1).Value
.Cells(y, 5).Value = WorksheetFunction.Sum(Range("E" & i & ":E" & y - 1)) .Cells(y, 1).Value = "Sum of " & .Cells(i, 1).Value y = i End If Next i End With End Sub
Re: add new row with formula...some problem with macro
Based on your last post it seems that you are satisfied with the solution(s) you've received but you haven't marked your thread as "SOLVED".
For the meantime I'll do it for you.
How?
New quick method:
Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.
Or you can use this way:
How to mark a thread Solved
Go to the first post
Click edit
Click Go Advanced
Just below the word Title you will see a dropdown with the word No prefix.
Change to Solved
Click Save
Note:
You can also thank those who have helped you by clicking the small star icon located in the lower left corner of the post in which the help was given.
By doing so you can add to the reputation(s) of those who helped and shared their time in helping you.
I think people forget the word "THANK YOU!!!!" Do you still know it???
There is a little star ( ADD REPUTATION ) below those person who helped you. Click it to say your "PRIVATE APPRECIATION TO THEIR EFFORT ON THEIR CONTRIBUTIONS "
Bookmarks