Loop to Collect Labels and Formulas on Dynamic Columns

荒凉一梦 提交于 2019-12-11 17:15:00

问题


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.

来源:https://stackoverflow.com/questions/52320226/loop-to-collect-labels-and-formulas-on-dynamic-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!