View Single Post
 
Old 11-25-2020, 11:06 PM
Purfleet Purfleet is offline Windows 10 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, 5 views)
Reply With Quote