+ Reply to Thread
Results 1 to 5 of 5

NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

Hybrid View

  1. #1
    Registered User
    Join Date
    08-28-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    14

    NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

    I need help repeating a process that takes forever by hand. I want to first calculate a column (Cumm BOE) for each entryl on a spreadsheet.

    1. Take BOE on row 5 and place the first sum in Cumm BOE column. (= BOE cell)
    2. Calculate row 6 Cumm BOE by adding row 5 Cumm BOE to row 6 BOE for total. (Cumm BOE is just a running total of all oil & gas produced)
    3. Select the cell with the new cumm BOE formula on on row 6 and copy it down the column to figure cumm BOE.
    5. Select both columns (BOE & Cumm BOE) and formatt to 0 decimals.
    6. Repeat this procedure on every 7th column (Cumm BOE) for the remainder of the worksheet.

    Note: Many times I have 400-500 wells in a row, the example attached shows only 119. The rows will be determined by how many rusults have been reported, so the number of rows could be 3 or 1000... Depends on how long the well has been in production.

    I am open to using any commands that shorten or simplify this process as long as I can get the document formatted properly and get the desired results.

    Any guidence would be appreciated.

    Thank You
    Attached Files Attached Files
    Last edited by sharahoff; 10-03-2012 at 05:01 PM.

  2. #2
    Forum Expert
    Join Date
    01-15-2007
    Location
    Brisbane, Australia
    MS-Off Ver
    2007
    Posts
    6,591

    Re: NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

    Hi

    Try this
    Sub aaa()
      For i = 7 To Cells(4, Columns.Count).End(xlToLeft).Column Step 7
        Cells(5, i).Formula = "=" & Cells(5, i - 1).Address
        Cells(6, i).Formula = "=" & Cells(5, i).Address(rowabsolute:=False, columnabsolute:=False) & "+" & Cells(6, i - 1).Address(rowabsolute:=False, columnabsolute:=False)
        Cells(6, i).AutoFill Destination:=Range(Cells(6, i), Cells(Rows.Count, i - 1).End(xlUp).Offset(0, 1))
      Next i
      
    End Sub
    rylo

  3. #3
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

    @sharaoff,

    Just noticed this post and seen that its another step for the code I coded for you earlier today. I just added the formulas to the code.

    Sub abc()
     Const shMaster As String = "MasterData"
     Const shResults As String = "ResultsPage"
     Dim i As Long, ii As Long, ptr As Long, icol As Long
     Dim a, x, y
     
     With Worksheets(shMaster)
        a = .Range("a1").CurrentRegion
     End With
     
     With CreateObject("Scripting.Dictionary")
        .CompareMode = 1
        For i = 2 To UBound(a)
            x = Join(Array(a(i, 1), a(i, 2), a(i, 3)), ",")
            If Not .Exists(x) Then
                .Item(x) = Join(Array(a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10)), ",")
            Else
                .Item(x) = .Item(x) & "," & Join(Array(a(i, 6), a(i, 7), a(i, 8), a(i, 9), a(i, 10)), ",")
            End If
        Next
        a = .Items
        x = .Keys
     End With
     
     icol = 4
     ptr = 5
     With Worksheets(shResults)
        .Cells.Clear
        For i = LBound(x) To UBound(x)
           .Cells(1, icol).Resize(3) = WorksheetFunction.Transpose(Split(x(i), ","))
            With .Cells(4, icol - 2).Resize(, 6)
                .Value = Array("production Date", "gas", "oil", "water", "BOE", "Cumm BOE")
                .Borders.LineStyle = xlContinuous
            End With
                y = Split(a(i), ",")
                For ii = LBound(y) To UBound(y) Step 5
                    With .Cells(ptr, icol - 2).Resize(, 6)
                        .Value = Array(y(ii), y(ii + 1), y(ii + 2), y(ii + 3), y(ii + 4), "")
                        .Borders.LineStyle = xlContinuous
                    End With
                    With .Cells(ptr, icol - 2) '<===== Add formulas to Cumm BOE
                        If ptr = 5 Then
                            .Offset(, 5).Value = "=" & .Offset(, 4).Address
                        Else
                            .Offset(, 5).Value = "=" & .Offset(-1, 5).Address & "+" & .Offset(, 4).Address
                        End If
                    End With
                    ptr = ptr + 1
                Next
                ptr = 5
            icol = icol + 7
        Next
     End With
    End Sub
    Thanks,
    Mike

    If you are satisfied with the solution(s) provided, please mark your thread as Solved.
    Select Thread Tools-> Mark thread as Solved.

  4. #4
    Registered User
    Join Date
    08-28-2012
    Location
    Houston
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

    Thank you Mike! Worked perfect!

    Rylo, thank you for your post as well.

  5. #5
    Forum Expert mike7952's Avatar
    Join Date
    12-17-2011
    Location
    Florida
    MS-Off Ver
    Excel 2007, Excel 2016
    Posts
    3,551

    Re: NEED HELP: Trying calculate a formula across a spreadsheet every 7th coulumn

    Your welcome... "barrel of oil", I used to be a rough neck in the north east drilling gas wells.

+ 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