+ Reply to Thread
Results 1 to 5 of 5

Column Subtraction

Hybrid View

  1. #1
    Registered User
    Join Date
    05-21-2019
    Location
    Cleveland, Ohio
    MS-Off Ver
    Office 16
    Posts
    12

    Column Subtraction

    Good morning,

    I have a column that populates from a formula, some are blank and some have values.. The column has no values from A1 thru A45. A46, has a value. and from A49 thru A75 the cells are empty. While cell A76 has a value. I need to tell my worksheet to subtract the two values, A46-A76. However, the column has about 22,000 values at different cells in the column. The formula needs to be able to "skip" the blank cells and subtract the two closest cells with value. The next subtraction could look like, A109-A127, A143-A166 the cells with values are not proportionally incremented. The column is too large to go through and put a subtraction formula for each instance. Any help would be appreciates. Thanks.

  2. #2
    Forum Expert avk's Avatar
    Join Date
    07-12-2007
    Location
    India
    MS-Off Ver
    Microsoft Office 2013
    Posts
    3,279

    Re: Column Subtraction

    Your data "A1" to "A166"
    In "B1"
    Formula: copy to clipboard
    =IFERROR(INDEX($A$1:$A$166,SMALL(INDEX(NOT(ISBLANK($A$1:$A$166))*ROW($A$1:$A$166),0),COUNTBLANK($A$1:$A$166)+ROW(A1))),"")

    ensure pressing shift+ctrl+enter
    copy paste down till blank.


    atul


    If my answer (or that of other members) has helped you, please say "Thanks" by clicking the Add Reputation button at the foot of one of their posts.

    Also: if your problem is solved, please take the time to mark your thread as SOLVED by going to the top of your first post, selecting "Thread Tools" and then "Mark thread as solved".

  3. #3
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Column Subtraction

    See attached file.
    Click the "Run" button and column B and C will list cell references for two consecutive non-zero values in column A.
    Column d will have the difference.

    here's the simple macro:
    Sub subtraction()
    Dim lr, x, y As Long
    Dim value1, value2 As Long
    
    With Worksheets("Sheet1")
    lr = .Range("A" & Rows.Count).End(xlUp).Row
    End With
    y = 1
    With ActiveSheet
    For x = 1 To lr
        If .Range("A" & x).Value > 0 Then
            If value1 > 0 Then
            .Range("B" & y).Value = "A" & x
            value2 = .Range("A" & x).Value
            Else: value1 = .Range("A" & x).Value
            .Range("C" & y).Value = "A" & x
            End If
            If value2 > 0 Then
            .Range("D" & y).Value = value2 - value1
            y = y + 1
            value1 = 0
            value2 = 0
            End If
        End If
    Next x
    End With
        
        
    
    
    
    
    End Sub
    Attached Files Attached Files
    1. Click on the * Add Reputation if you think this helped you
    2. Mark your thread as SOLVED when question is resolved

    Modytrane

  4. #4
    Registered User
    Join Date
    05-21-2019
    Location
    Cleveland, Ohio
    MS-Off Ver
    Office 16
    Posts
    12

    Re: Column Subtraction

    I implemented this into my worksheet with all of the data and it threw me an error. Of the entirety of the worksheet the data that needs subtracting is in column N, and there are 22500 rows.

  5. #5
    Forum Expert
    Join Date
    11-27-2007
    Location
    New Jersey, USA
    MS-Off Ver
    2013
    Posts
    1,669

    Re: Column Subtraction

    Did you modify the macro to account for column change?

    Or

    Attach copy of your worksheet with maybe few hundred entries.

+ 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. Range Subtraction / Matrix Subtraction - Large data set
    By excelrabbit in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 11-20-2015, 07:07 AM
  2. [SOLVED] Subtraction of Column Ranges within Averageifs Function
    By lukazi in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 02-15-2014, 03:48 AM
  3. Subtraction of Column Ranges within Averageifs Function
    By lukazi in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-14-2014, 04:32 AM
  4. sum of subtraction every two row
    By vietdieu in forum Excel General
    Replies: 16
    Last Post: 01-22-2012, 05:07 PM
  5. Replies: 1
    Last Post: 01-29-2011, 05:05 PM
  6. subtraction
    By Kmac in forum Excel General
    Replies: 2
    Last Post: 04-06-2010, 05:53 PM
  7. [SOLVED] Subtraction formula for consecutive cells in a column, skipping blanks
    By elton@rogers.com in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-15-2005, 08:05 PM

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