Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #2  
Old 11-25-2020, 11:06 PM
Purfleet Purfleet is offline Subtract contiguous values from top cell, continuously in column, till end Windows 10 Subtract contiguous values from top cell, continuously in column, till end Office 2019
Expert
 
Join Date: Jun 2020
Location: Essex
Posts: 345
Purfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to beholdPurfleet is a splendid one to behold
Default

Try this, seems to work


Code:
Sub AutoSum()
  'https://stackoverflow.com/questions/24047824/vba-excel-loop-assistance
  
  Dim Area As Range, MyColumn As String, startNum As String, SumAddr As String
  Dim i As Long
  
  For i = 2 To 9  'Columns B to E
    
    For Each Area In Columns(i).SpecialCells(xlConstants, xlNumbers).Areas
      If Area.Count <= 1 Then GoTo Skip
      
      
      startNum = Area.Resize(1, 1).Address(False, False)
       SumAddr = Area.Offset(1, 0).Resize(Area.Count - 1, 1).Address(False, False)
      Area.Offset(Area.Count, 0).Resize(1, 1).Formula = "=" & startNum & "-SUM(" & SumAddr & ")"
       Area.Offset(Area.Count, 0).Resize(1, 1).Font.Color = vbRed
Skip:
    Next Area
  Next i
End Sub
Attached Files
File Type: xlsm Copy of Substract contiguous values_Purfleet.xlsm (19.0 KB, 7 views)
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Subtract contiguous values from top cell, continuously in column, till end Novice needs: Complicated running totals adding substracting non contiguous cells contiguous columns innkeeper9 Excel 5 08-30-2016 04:43 PM
Subtract value from one cell into another otuatail Excel 3 02-01-2016 03:21 AM
Mouseover cell to indicate mouse pointer location based on Specific Row/Column values bolandk Excel 1 05-15-2014 08:22 AM
Summing Non Contiguous Cells in a Row or Column Joe Ottenhof Excel 4 12-19-2012 04:13 AM
From a particular cell till the end of the same column tinfanide Excel 3 08-10-2011 05:09 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 04:53 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft