vba - VBA将一个子的范围传递给另一个子
问题描述
我想将范围:将 Sub FoundVisit() 的 cell = bd.Range(FoundColumn & StartRow & ":" & FoundColumn & LastRow) 设置为另一个 Sub SumVisit(),然后对所有访问求和。
- Sub FoundVisit() :找到标题等于访问的列并设置范围。
- Sub SumVisit() :对 Sub FoundVisit() 找到的范围求和。
Sub FoundVisit(StartRow As Long, LastRow As Long, FoundColumn As String, StringToFind As String, ResultRange As Range, cell As Range)
Dim bd As Worksheet: Set bd = Sheets("BDD")
Dim rf As Worksheet: Set rf = Sheets("REF")
StringToFind = rf.Range("D2").Value
Set ResultRange = bd.Cells.Find(What:=StringToFind, LookIn:=xlValues, LookAt:=xlWhole, SearchOrder:=xlByColumns)
If ResultRange Is Nothing Then
MsgBox "Nothing"
Else
'Get the row after the header
StartRow = ResultRange.Row + 1
'Column of the header
FoundColumn = Split(Cells(, ResultRange.Column).Address, "$")(1)
'Last row under that header
LastRow = bd.Range(FoundColumn & bd.Rows.Count).End(xlUp).Row
'The range that I need
Set cell = bd.Range(FoundColumn & StartRow & ":" & FoundColumn & LastRow)
End If
End Sub
Sub SumVisit()
With Sheets("SUMMARY")
Sheets("SUMMARY").Label1 = Application.WorksheetFunction.Sum(FoundVisit)
End With
End Sub
解决方案
推荐阅读
- c# - 需要显示具有自定义对齐方式的列表视图项
- wpf - WPF 日历中 PART_HeaderButton 的 NullReferenceException
- python - 如何将关键事件发送到python中的非活动窗口
- java - 执行appium脚本时遇到javapath错误
- python - 作为 groupby 查询的结果,如何从 DF 中删除行?
- php - 如何将此 RewriteRule 重定向到正确的页面?
- elasticsearch - ElasticSearch DSL:也可以查询自定义标签
- java - 使用 StackLayout 我只想在选择标志时显示一个表
- java - 为 HttpServletRequest 使用 Swagger 文档
- powerbi - 创建包含年度摘要和最新值的表