Results 1 to 5 of 5

Column Subtraction

Threaded View

  1. #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

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