excel - 整个工作簿的 SUMIF
问题描述
一直在寻找解决此问题的工作电子表格,但尚未找到解决方案。我的工作簿目前包括每个客户在个人工作表上的每日股票活动(工作表标题为 '5.9.2018、6.9.2018、7.9.2018 等)。该工作簿还包含一个主工作表,旨在提供这些每日工作表的每周和每月摘要(下面的主工作表屏幕截图):
我想做的是将 sumifs 或类似功能合并到我的 vba 中,它将使用主表中的客户名称作为参考,并检查每个每日工作表中的预定列以生成每月和每周的数据。任何有关如何将其合并到 VBA 中的指导将不胜感激,因为我是 VBA 的相对新手,并且无法自己找到解决方案。
谢谢
编辑:当前的 VBA 包括在下面
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
解决方案
推荐阅读
- python - 使用 soup.find() 查找跨度
- reactjs - 如何使条形图和散点出现在彼此下方?
- ruby-on-rails - 如果为空,Rails 设置模型属性
- python - BeautifulSoup list index out of range error with multiple .contents
- java - Android 在 ROOM 数据库中插入大量数据
- google-chrome-extension - 在 chrome 扩展弹出窗口上按下“单击”按钮时,应填写表单
- jquery - 被 CORS 阻止(从 html 站点向我的 Laravel 站点发送请求)
- python - Django Likes 计数未在帖子中显示任何更改
- python - 破解我的针织机 - 没有名为 image 的模块
- java - 单击菜单项时如何打开底部工作表| 安卓工作室