ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   SUMIF in VBA (https://www.excelbanter.com/excel-programming/317140-sumif-vba.html)

LeeBoWadd[_3_]

SUMIF in VBA
 

:eek: Found my own answer.

Sub SumIfer()
Dim EnderA As String
Dim EnderC As String
Dim EnderD As String
Dim EnderE As Variant
Dim Acta As String

Range("A6").Select
Selection.Sort Key1:=Range("A6"), Order1:=xlAscending
Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Range("A7").Select
EnderA = Range(Selection, Selection.End(xlDown)).Address
Debug.Print EnderA
EnderC = Range(Selection, Selection.End(xlDown)).Offset(0
2).Address
Debug.Print EnderC
EnderD = Range(Selection, Selection.End(xlDown)).Offset(0
3).Address
Debug.Print EnderD
EnderE = Range(Selection, Selection.End(xlDown)).Offset(0
4).Address
Debug.Print EnderE
Range(EnderE).Formula = _
"=IF(A7=A6,"""",SUMIF((" & EnderA & "),A7,(" & EnderC & "))"
"-SUMIF((" & EnderA & "),A7,(" & EnderD & ")))"
Range("A7").Select
Range(Selection, Selection.End(xlDown)).Offset(0, 4).Copy
Range(Selection, Selection.End(xlDown)).Offset(0, 4).PasteSpecia
xlPasteValues
With Selection
.HorizontalAlignment = xlRight
.Style = "Comma"
.Font.ColorIndex = 5
.NumberFormat = "#,##0.00_);[Red](#,##0.00)"
End With
Columns("C:D").Select
Selection.Style = "Comma"
Range("A1").Select
Application.CutCopyMode = Fals

--
LeeBoWad
-----------------------------------------------------------------------
LeeBoWadd's Profile: http://www.excelforum.com/member.php...fo&userid=1655
View this thread: http://www.excelforum.com/showthread.php?threadid=31409



All times are GMT +1. The time now is 06:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com