SUMIF across entire workbook
up vote
-1
down vote
favorite
Have been looking to solve this issue for a work spreadsheet but yet to find a solution. My workbook currently includes daily stock activity per client on individual worksheets (worksheets titled '5.9.2018, 6.9.2018, 7.9.2018 and so forth). The workbook also contains a master worksheet which is designed to provide weekly and monthly summaries of these daily worksheets (screenshot of master sheet below):
What I would like to do is incorporate a sumifs or similar function into my vba which will use the client name from the master sheet as a reference and check pre-determined columns across each daily worksheet to produce those monthly and weekly figures. Any guidance on how to incorporate this into a VBA would be greatly appreciated as I am a relative newcomer to VBA and have not been able to find the solution on my own.
Thank you
Edit: Current VBA included below
Sub AutoSum()
Dim wscount As Long
Dim i As Long
wscount = ActiveWorkbook.Worksheets.Count
For i = 1 To wscount
Sheets(i).Select
Range("K4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
Dim cel1 As String, cel2 As String
cel1 = ActiveCell.Offset(-2, 0).End(xlUp).Address
cel2 = ActiveCell.Offset(-1).Address
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"
Next i
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To =
.CC = ""
.BCC = ""
.Subject = "Today's Trades" & Date
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
excel vba sumifs
add a comment |
up vote
-1
down vote
favorite
Have been looking to solve this issue for a work spreadsheet but yet to find a solution. My workbook currently includes daily stock activity per client on individual worksheets (worksheets titled '5.9.2018, 6.9.2018, 7.9.2018 and so forth). The workbook also contains a master worksheet which is designed to provide weekly and monthly summaries of these daily worksheets (screenshot of master sheet below):
What I would like to do is incorporate a sumifs or similar function into my vba which will use the client name from the master sheet as a reference and check pre-determined columns across each daily worksheet to produce those monthly and weekly figures. Any guidance on how to incorporate this into a VBA would be greatly appreciated as I am a relative newcomer to VBA and have not been able to find the solution on my own.
Thank you
Edit: Current VBA included below
Sub AutoSum()
Dim wscount As Long
Dim i As Long
wscount = ActiveWorkbook.Worksheets.Count
For i = 1 To wscount
Sheets(i).Select
Range("K4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
Dim cel1 As String, cel2 As String
cel1 = ActiveCell.Offset(-2, 0).End(xlUp).Address
cel2 = ActiveCell.Offset(-1).Address
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"
Next i
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To =
.CC = ""
.BCC = ""
.Subject = "Today's Trades" & Date
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
excel vba sumifs
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a=SUMIFS
formula you can use?
– Pᴇʜ
Nov 7 at 9:02
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
1
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
1
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
Have been looking to solve this issue for a work spreadsheet but yet to find a solution. My workbook currently includes daily stock activity per client on individual worksheets (worksheets titled '5.9.2018, 6.9.2018, 7.9.2018 and so forth). The workbook also contains a master worksheet which is designed to provide weekly and monthly summaries of these daily worksheets (screenshot of master sheet below):
What I would like to do is incorporate a sumifs or similar function into my vba which will use the client name from the master sheet as a reference and check pre-determined columns across each daily worksheet to produce those monthly and weekly figures. Any guidance on how to incorporate this into a VBA would be greatly appreciated as I am a relative newcomer to VBA and have not been able to find the solution on my own.
Thank you
Edit: Current VBA included below
Sub AutoSum()
Dim wscount As Long
Dim i As Long
wscount = ActiveWorkbook.Worksheets.Count
For i = 1 To wscount
Sheets(i).Select
Range("K4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
Dim cel1 As String, cel2 As String
cel1 = ActiveCell.Offset(-2, 0).End(xlUp).Address
cel2 = ActiveCell.Offset(-1).Address
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"
Next i
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To =
.CC = ""
.BCC = ""
.Subject = "Today's Trades" & Date
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
excel vba sumifs
Have been looking to solve this issue for a work spreadsheet but yet to find a solution. My workbook currently includes daily stock activity per client on individual worksheets (worksheets titled '5.9.2018, 6.9.2018, 7.9.2018 and so forth). The workbook also contains a master worksheet which is designed to provide weekly and monthly summaries of these daily worksheets (screenshot of master sheet below):
What I would like to do is incorporate a sumifs or similar function into my vba which will use the client name from the master sheet as a reference and check pre-determined columns across each daily worksheet to produce those monthly and weekly figures. Any guidance on how to incorporate this into a VBA would be greatly appreciated as I am a relative newcomer to VBA and have not been able to find the solution on my own.
Thank you
Edit: Current VBA included below
Sub AutoSum()
Dim wscount As Long
Dim i As Long
wscount = ActiveWorkbook.Worksheets.Count
For i = 1 To wscount
Sheets(i).Select
Range("K4").Select
Selection.End(xlDown).Select
ActiveCell.Offset(2, 0).Select
Dim cel1 As String, cel2 As String
cel1 = ActiveCell.Offset(-2, 0).End(xlUp).Address
cel2 = ActiveCell.Offset(-1).Address
ActiveCell.Value = "=sum(" & (cel1) & ":" & (cel2) & ")"
Next i
Dim rng As Range
Dim OutApp As Object
Dim OutMail As Object
Set rng = Nothing
On Error Resume Next
Set rng = Selection.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If rng Is Nothing Then
MsgBox "The selection is not a range or the sheet is protected" & _
vbNewLine & "please correct and try again.", vbOKOnly
Exit Sub
End If
With Application
.EnableEvents = False
.ScreenUpdating = False
End With
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To =
.CC = ""
.BCC = ""
.Subject = "Today's Trades" & Date
.HTMLBody = RangetoHTML(rng)
.Send 'or use .Display
End With
On Error GoTo 0
With Application
.EnableEvents = True
.ScreenUpdating = True
End With
Set OutMail = Nothing
Set OutApp = Nothing
End Sub
Function RangetoHTML(rng As Range)
Dim fso As Object
Dim ts As Object
Dim TempFile As String
Dim TempWB As Workbook
TempFile = Environ$("temp") & "" & Format(Now, "dd-mm-yy h-mm-ss") & ".htm"
rng.Copy
Set TempWB = Workbooks.Add(1)
With TempWB.Sheets(1)
.Cells(1).PasteSpecial Paste:=8
.Cells(1).PasteSpecial xlPasteValues, , False, False
.Cells(1).PasteSpecial xlPasteFormats, , False, False
.Cells(1).Select
Application.CutCopyMode = False
On Error Resume Next
.DrawingObjects.Visible = True
.DrawingObjects.Delete
On Error GoTo 0
End With
With TempWB.PublishObjects.Add( _
SourceType:=xlSourceRange, _
Filename:=TempFile, _
Sheet:=TempWB.Sheets(1).Name, _
source:=TempWB.Sheets(1).UsedRange.Address, _
HtmlType:=xlHtmlStatic)
.Publish (True)
End With
Set fso = CreateObject("Scripting.FileSystemObject")
Set ts = fso.GetFile(TempFile).OpenAsTextStream(1, -2)
RangetoHTML = ts.readall
ts.Close
RangetoHTML = Replace(RangetoHTML, "align=center x:publishsource=", _
"align=left x:publishsource=")
TempWB.Close savechanges:=False
Kill TempFile
Set ts = Nothing
Set fso = Nothing
Set TempWB = Nothing
End Function
excel vba sumifs
excel vba sumifs
edited Nov 7 at 9:25
Pᴇʜ
18.6k42549
18.6k42549
asked Nov 7 at 8:58
NHure92
306
306
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a=SUMIFS
formula you can use?
– Pᴇʜ
Nov 7 at 9:02
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
1
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
1
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15
add a comment |
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a=SUMIFS
formula you can use?
– Pᴇʜ
Nov 7 at 9:02
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
1
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
1
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a
=SUMIFS
formula you can use?– Pᴇʜ
Nov 7 at 9:02
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a
=SUMIFS
formula you can use?– Pᴇʜ
Nov 7 at 9:02
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
1
1
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
1
1
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
I don't think you even need VBA for this task. Something like this should do it for you.
=SUMPRODUCT(SUMIF(INDIRECT("'"&sheets&"'!"&"rng"),criteria,INDIRECT("'"&sheets&"'!"&"sumrng")))
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I don't think you even need VBA for this task. Something like this should do it for you.
=SUMPRODUCT(SUMIF(INDIRECT("'"&sheets&"'!"&"rng"),criteria,INDIRECT("'"&sheets&"'!"&"sumrng")))
add a comment |
up vote
0
down vote
I don't think you even need VBA for this task. Something like this should do it for you.
=SUMPRODUCT(SUMIF(INDIRECT("'"&sheets&"'!"&"rng"),criteria,INDIRECT("'"&sheets&"'!"&"sumrng")))
add a comment |
up vote
0
down vote
up vote
0
down vote
I don't think you even need VBA for this task. Something like this should do it for you.
=SUMPRODUCT(SUMIF(INDIRECT("'"&sheets&"'!"&"rng"),criteria,INDIRECT("'"&sheets&"'!"&"sumrng")))
I don't think you even need VBA for this task. Something like this should do it for you.
=SUMPRODUCT(SUMIF(INDIRECT("'"&sheets&"'!"&"rng"),criteria,INDIRECT("'"&sheets&"'!"&"sumrng")))
answered Nov 7 at 18:16
ryguy72
3,6661619
3,6661619
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53186206%2fsumif-across-entire-workbook%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Please include the code you already have tried in your question. Also it is necessary that you ask a question to that code and tell where you got stuck or errors. Reading How to Ask might help to improve your question. • Also why do you need VBA if there is a
=SUMIFS
formula you can use?– Pᴇʜ
Nov 7 at 9:02
Hi, I've edited and included my code. My code currently provides a sum total for column K on each worksheet and embeds the active worksheet into an outlook email and sends it out. As for codes for sumif, I've been reading but have been unable to find anything thus far which is why I'm here looking for possible solutions. The VBA has been requested by management, it is out of my control
– NHure92
Nov 7 at 9:12
First of all you should read and apply: How to avoid using Select in Excel VBA • At least for me it is still very unclear what exactly you try to sum (to less information, see also Minimal, Complete, and Verifiable example). But have a look at the WorksheetFunction.SumIfs Method
– Pᴇʜ
Nov 7 at 9:28
1
Possible duplicate of VBA - sum totals to a master worksheet
– OwlsSleeping
Nov 7 at 10:13
1
The same question has been asked daily for weeks. If this is materially different to those other questions please focus on the specific point that needs help.
– OwlsSleeping
Nov 7 at 10:15