+ Reply to Thread
Results 1 to 6 of 6

add new row with formula...some problem with macro

  1. #1
    Registered User
    Join Date
    10-28-2012
    Location
    Poland
    MS-Off Ver
    Excel 2007/2010
    Posts
    94

    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 
    Attached Images Attached Images
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: add new row with formula...some problem with macro

    Perhaps,

    Please Login or Register  to view this content.
    Attached Files Attached Files

  3. #3
    Registered User
    Join Date
    10-28-2012
    Location
    Poland
    MS-Off Ver
    Excel 2007/2010
    Posts
    94

    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 LongAs Long
    Dim x 
    As LongAs Long

    With ActiveSheet
    LR 
    = .Cells(Rows.Count1).End(xlUp).Row
        y 
    LR 1
        
    For LR To 2 Step -1
            
    If Len(Trim(.Cells(i1).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 

  4. #4
    Forum Expert
    Join Date
    12-15-2009
    Location
    Chicago, IL
    MS-Off Ver
    Microsoft Office 365
    Posts
    3,177

    Re: add new row with formula...some problem with macro

    just add the .borders statement.

    I am guessing the syntax, you may get an error if I coded incorrectly.

    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    10-28-2012
    Location
    Poland
    MS-Off Ver
    Excel 2007/2010
    Posts
    94

    Re: add new row with formula...some problem with macro

    Thanks. Great tip. Everything work excellent!!!

  6. #6
    Forum Moderator vlady's Avatar
    Join Date
    09-22-2011
    Location
    Philippines - OLSHCO -Guimba-Nueva Ecija
    MS-Off Ver
    2021
    Posts
    4,361

    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 "

    Regards,
    Vladimir

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1