Loop to Collect Labels and Formulas on Dynamic Col

2019-08-29 12:13发布

Example Code:

Sheet1 has data format sheet3 has basic desired output

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

Code to collect labels:

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

Goal: (1) Loop to collect data labels and associated calculations from dynamic column sizes (averages, min, max, countif, sum, etc). (2) Get ALL date and ALL state of charge points data (columns B and N) into two columns for a graph.

0条回答
登录 后发表回答