VBA передать диапазон саба к другому сабвуферу - PullRequest
0 голосов
/ 27 февраля 2020

Я хочу передать диапазон: Set cell = bd.Range (FoundColumn & StartRow & ":" & FoundColumn & LastRow) из Sub FoundVisit () в другой 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
...