编程目标:
1)循环并存储各个统计信息:
a。扫描序列号,偏移并为每个收集以下各项: 一世。 PL#
ii。固件版本
iii。容量(下面的单元格中的所有内容)
iv。技术(下面的单元格中的所有内容)
v。电池#
对于每个PL,以下计算...
vi。平均,最小,最大(*充电状态百分比)
vii。平均,最小,最大(温度)
viii。最小,最大,平均(我开始充电(A))
ix。出现次数等于。时间为“ = 0”,“(1,419)”,“(420,839)”,“ = 840”
x。出现次数低级别“是”和“否”
xi。是/(是+否)的比例
xii。总和(Disch。Ah-)
xiii。总和(Ah +费用)
xiv。 (Ah + / Ah-)的比例
2)将表输出到新工作表:
a。使用标题分别为i-xii的表格创建表
b。每个单独的PL#及其i-xii的值
c。相等的总和。存储在所有数据中的时间
3)将图形输出到新工作表:
a。所有日期(y)和*%充电状态(x)二维线图,y轴0-100,带有
绿线恒定为100,红线恒定为20
b。所有日期和温度的2D折线图,其恒定红线为138
我正在研究(1)。这就是我将如何扫描和收集每个块的方法...
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
我想做什么:。我想输出一个表,其中包含收集的标签和相应的计算。到目前为止,我拥有的循环会获得标签。
示例文件:
https://drive.google.com/open?id=1vDqnt2aHL06xB2Fg9k5MZ2WeCefqQZ1n 1
答案 0 :(得分:1)
这需要更多的编码,您可以对其进行更多的参数设置,而且如果导出excel文件格式不会更改,则保持简单有好处。我计算了平均温度并将其插入您的阵列中。收集完所有数据后,您需要转置数组并将其粘贴到工作表中:
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
Dim rng As Range
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 6, 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#
'define the data block for the battery
Set rng = aCell.CurrentRegion 'data block for one battery
Set rng = rng.Offset(6, 0)
Set rng = rng.Resize(rng.Rows.Count - 6, rng.Columns.Count)
'now range is defined, run the calculations using the worksheet functions, or use a loop over the range columns
'### calculate avg, min and max temperature (8th column in block)
ArrPK(6, PkCounter) = Application.WorksheetFunction.Average(rng.Columns(8)) 'average temperature
PkCounter = PkCounter + 1
End If
Next
End With
End Sub