循环以在动态列上收集标签和公式

时间:2018-09-13 19:03:27

标签: excel vba loops worksheet-function

示例代码:

Sheet1具有数据格式 sheet3具有基本的期望输出

https://drive.google.com/open?id=1aXn230d-7zh68w6FJN0qpZ6R0rI31HSE

收集标签的代码:

Sub GetData()

Dim ArrPK() As String, SearchString As String
Dim SerialNo As Range, aCell As Range
Dim ws As Worksheet
Dim PkCounter As Long
Dim LstBox As msforms.ListBox

Set ws = ThisWorkbook.Sheets("Sheet1")
SearchString = "Serial#"
Set LstBox = UserForm1.ListBox1

PkCounter = 1

With ws
    Set SerialNo = .Range("A1:A" & .Cells(.Rows.Count, "A").End(xlUp).Row)

    For Each aCell In SerialNo
        If aCell.Value2 = SearchString Then
            ReDim Preserve ArrPK(1 To 5, 1 To PkCounter)
            ArrPK(1, PkCounter) = aCell.Offset(0, 1) 'Serial#
            ArrPK(2, PkCounter) = aCell.Offset(1, 1) 'Firmware#
            ArrPK(3, PkCounter) = aCell.Offset(3, 1) 'Capacity
            ArrPK(4, PkCounter) = aCell.Offset(3, 3) 'Technology
            ArrPK(5, PkCounter) = aCell.Offset(3, 11) 'Battery#
       'Collected information labels, now run calculations...
            PkCounter = PkCounter + 1
        End If
    Next
End With
End Sub

目标:(1)循环从动态列大小(平均值,最小值,最大值,计数,和等)中收集数据标签。 (2)将所有日期和所有充电点数据状态(列B和N)分成两列以显示图表。

0 个答案:

没有答案