+ Reply to Thread
Results 1 to 3 of 3

TEST_MACRO_insert row on value change and calc

  1. #1
    Forum Contributor
    Join Date
    02-28-2012
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    542

    TEST_MACRO_insert row on value change and calc

    In the worksheet I want to calculate the bifurcated numbers belonging to one share. have to insert a row after every valuechange based on ( SECURITY (COL F) TRADE TYPE(COL G) and calculate the qty,rate and the total price of each symbol tradetype wise ,ie,buy or sell. pls have a look at the second sheet in which i have illustrated the outcome. I have attached a macro which works partially. kindly have an edit on the macro so that it should work perfectly in the expected route. I have noted the points to be corrected with arrow...thanks in advance.



    ATTACHED
    1. ORGINAL FILE-edited 100722- version
    2. MACRO ENABLED FILE
    3. ERROR TO BE CORRECTED IN THE CODE FILE---Named code does not work properly

    Sub rsnMacro()
    Dim lngR As Long
    Dim iC As Integer

    lngR = 6
    iC = 1

    While Cells(lngR, 6).Value <> ""
    If Cells(lngR, 6).Value <> Cells(lngR + 1, 6).Value Or Cells(lngR, 7).Value <> Cells(lngR + 1, 7).Value Then
    '1.Insert a row after every value change in col f (symbol) as well as col g (trade date)
    lngR = lngR + 1
    Rows(lngR).Insert
    '2.in the new row type COMBO in col A
    Cells(lngR, 1).Value = "COMBO"
    With Cells(lngR, 1).Resize(1, 12)
    '3.highlight the contents in the new row with color yello and charaters in color red.
    .Interior.ColorIndex = 6
    .Font.ColorIndex = 3
    '4.in the new row copy paste the contents from the just above row.from col D:G
    Intersect(.Cells, Range("B:G")).Value = Intersect(.Cells, Range("B:G")).Offset(-1).Value
    Intersect(.Cells, Range("K:K")).Value = Intersect(.Cells, Range("K:K")).Offset(-1).Value


    '5.calculate the sum of a cluster(Same symbol, same date)in col H, else input the contents from the above ROW.
    'Have to make calculations in col H (sum total) in column I calculate average price AND in col J = sum QTY* PRICE.
    '7. in col j the formula should work. Qty* PRICE
    .Cells(1, 8).FormulaR1C1 = "=SUM(R[-" & iC & "]C:R[-1]C)"
    .Cells(1, 10).FormulaR1C1 = "=SUM(R[-" & iC & "]C:R[-1]C)"
    .Cells(1, 9).FormulaR1C1 = "=RC[1]/RC[-1]"
    End With
    iC = 1
    lngR = lngR + 1
    Else
    iC = iC + 1
    lngR = lngR + 1
    End If
    Wend

    End Sub
    Last edited by sumesh56; 07-10-2022 at 03:15 AM. Reason: Edited original file and code attached now

  2. #2
    Forum Expert
    Join Date
    05-30-2012
    Location
    The Netherlands
    MS-Off Ver
    Office 365
    Posts
    14,987

    Re: insert a row after every value change and calculate the figures above to the new row

    NON VBA solution

    With a pivot table to analyse the data.

    See the attached file.
    Last edited by oeldere; 07-03-2022 at 11:58 AM.
    Notice my main language is not English.

    I appreciate it, if you reply on my solution.

    If you are satisfied with the solution, please mark the question solved.

    You can add reputation by clicking on the star * add reputation.

  3. #3
    Forum Contributor
    Join Date
    02-28-2012
    Location
    india
    MS-Off Ver
    Excel 2013
    Posts
    542

    Re: insert a row after every value change and calculate the figures above to the new row

    oeldere ,thanks for the suggestion. this is not certainly what i wanted.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. How do you calculate figures held in multiple cells?
    By SteveBIM in forum Excel General
    Replies: 3
    Last Post: 03-26-2015, 05:21 PM
  2. Replies: 5
    Last Post: 05-16-2014, 04:35 PM
  3. Formula to Calculate Quarter & Yearly Figures
    By foxtrot1961 in forum Excel Formulas & Functions
    Replies: 12
    Last Post: 08-18-2013, 10:22 AM
  4. Conversion of an array of figures inputted into cells as word figures to Excel figures
    By Allan Simpson730 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-08-2013, 07:25 AM
  5. How to calculate year to date figures
    By Climaxgp in forum Excel General
    Replies: 9
    Last Post: 05-12-2009, 08:44 AM
  6. [SOLVED] calculate minus figures
    By Nigel in forum Excel General
    Replies: 1
    Last Post: 03-30-2005, 12:06 PM
  7. Calculate minus figures only
    By Nigel in forum Excel General
    Replies: 1
    Last Post: 03-30-2005, 08:45 AM

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