VB代码每行加下注释,本人不太会VB
b_sheet.Cells(x1 + 11, 1) = "保温时间"
For i = 1 To 16
i1 = i
b_sheet.Cells(x1 + 6, i + 1) = "第" + i1 + "点"
b_sheet.Cells(x1 + 7, i + 1) = High(i)
b_sheet.Cells(x1 + 8, i + 1) = Low(i)
b_sheet.Cells(i2 + 9, i + 1) = (High(i) - Low(i)) / 2
b_sheet.Cells(x1 + 10, i + 1) = Fo(i)
b_sheet.Cells(x1 + 11, i + 1) = Keep(i)
b_sheet.Cells(i2 + 4, 10) = "最大差值:"
b_sheet.Cells(i2 + 4, 14) = cha1
b_sheet.Cells(x1 + 13, 11) = "测试日期:"
b_sheet.Cells(x1 + 13, 12) = "2009年01月01日"
Next
UserForm1.Hide
End Sub
Private Sub UserForm_Click()
End Sub
'这是我学编程以来翻译的最蛋疼的一次代码了...
Private Sub CommandButton1_Click()
Set jl_sheet = Sheets("记录表") 'jl_sheet为"记录表"的表单
Set b_sheet = Sheets("报表") 'b_sheet为"报表"的表单
i3 = 0
x = 0
X1 = 1 '3个变量赋初值
For I = 1 To 16
Fo(I) = 0
Low(I) = 0
High(I) = 0
Keep(I) = 0
Next '给几个长度为16的数组赋初值
b_sheet.Cells(1, 5) = "温" '记录表的E1内容为"温"
b_sheet.Cells(1, 6) = "度" '记录表的F1内容为"度"
b_sheet.Cells(1, 7) = "记" '记录表的G1内容为"记"
b_sheet.Cells(1, 8) = "录" '记录表的H1内容为"录"
b_sheet.Cells(2, 9) = "编号:" '记录表的I2内容为"编号"
b_sheet.Cells(3, 1) = "时间" '记录表的A3内容为"时间"
b_sheet.Cells(3, 18) = "最高值" '记录表的第18列第3行内容为"最高值"
b_sheet.Cells(3, 19) = "最低值" '记录表的第19列第3行内容为"最低值"
b_sheet.Cells(3, 20) = "平均值" '记录表的第20列第3行内容为"平均值"
b_sheet.Cells(3, 21) = "差 值" '记录表的第21列第3行内容为"差值"
For I = 2 To 16
i1 = I - 1
b_sheet.Cells(3, I) = "第 " + i1 + "点"
Next '从"记录表"的第3列的第2行开始,给单元格赋值为"第 i-1点
i2 = jl_sheet.[a1].CurrentRegion.Rows.Count '给i2赋值为"报表的"A1所在区域的有效行数的最大值(有效行就是有数据的即为有效行)
s = jl_sheet.Cells(1, 1) '将报表的A1的内容赋给s
For I = 2 To i2 '循环体
x = x + 1
s = jl_sheet.Cells(I - 1, 1) 's遍历为第一列的的单元格数值
For j = 2 To 17
temp(j - 1) = jl_sheet.Cells(I - 1, j) 'temp()数组遍历"报表"中第一行第一列至I2(最后一行)第16列,这个矩形区域的值
Next
p1 = 0
h = 0
For m = 1 To 16
p1 = p1 + temp(m) 'p1将temp()的各个字符串连接起来
Next
p1 = p1 / 16 'p1重新赋值为p1的16分之一
For m = 1 To 16 '循环体
If m = 1 Then
L = temp(m) 'm=1时L永远为temp(1)的值,也就是"报表"第一列的值
ElseIf temp(m) < L Then
L = temp(m) '如果L比temp(m)大,那么将temp(m)赋给L,L为每一行中的最小值
End If
If temp(m) > h Then '如果temp(m)>h,则赋给h,h为temp(m)中的最大值
h = temp(m)
End If
Next
If Abs(p1 - L) > Abs(p1 - h) Then '如果temp(m)的平均值与最大值的差 要比 平均值与最小值的差 大的话
cha = Abs(p1 - L) '把平均值与最大值得差的绝对值赋给cha
Else
cha = Abs(p1 - h) '同理
End If
If (i3 = 0 And p1 > 121) Then '对于temp(m)的平均值温度大于121
For m = 1 To 12
Low(m) = temp(m) '那么将该组温度数据赋给low()数组
cha1 = cha 'cha1=cha
Next
i3 = 1
End If
For m = 1 To 16
If p1 > 121 Then
If Low(m) > temp(m) Then '将low()数组一直保持温度数据组的最小数据组
Low(m) = temp(m)
End If
End If
If High(m) < temp(m) Then '同上,不过是最大
High(m) = temp(m)
End If
If temp(m) >= 121 Then
Keep(m) = Keep(m) + 0.5 '如果temp()中值都大于121那么keep()递增0.5
End If
If temp(m) > 100 Then '如果temp()的值都大约100
f = (temp(m) - 121) / 10 '这个值就-121然后除以10
f = 10 ^ f
f = (0.5 * f)
Fo(m) = Fo(m) + f '这你妹的,能不能一起赋值完啊?Fo(m)=Fo(m)+0.5*10^((temp(m)-121)/10)
End If
Next
For j = 2 To 17
b_sheet.Cells(X1 + 3, 1) = s '将s值输出在"记录表"的(4,1)
b_sheet.Cells(X1 + 3, j) = temp(j - 1) '将temp()的数据输出在"记录表"的第4行第2列至第16列
Next
b_sheet.Cells(X1 + 3, 18) = h '"记录表"的第4行至最后一行+3第18列的值为h ,最高值
b_sheet.Cells(X1 + 3, 19) = L '"记录表"的第4行至最后一行+3第19列的值为L,最低值
b_sheet.Cells(X1 + 3, 20) = p1 '"记录表"的第4行至最后一行+3第20列的值为p1,平均值
b_sheet.Cells(X1 + 3, 21) = cha ''"记录表"的第4行至最后一行+3第21列的值为cha,差值
X1 = X1 + 1
x = 0
If p1 > 121 Then
If cha > cha1 Then '如果差值超过了cha1,那么保持cha1为最大差值
cha1 = cha
End If
End If
Next
b_sheet.Cells(X1 + 7, 1) = "最高值"
b_sheet.Cells(X1 + 8, 1) = "最低值"
b_sheet.Cells(X1 + 9, 1) = "波动度"
b_sheet.Cells(X1 + 10, 1) = "FH值"
b_sheet.Cells(X1 + 11, 1) = "保温时间" '文本内容
For I = 1 To 16
i1 = I
b_sheet.Cells(X1 + 6, I + 1) = "第" + i1 + "点"
b_sheet.Cells(X1 + 7, I + 1) = High(I)
b_sheet.Cells(X1 + 8, I + 1) = Low(I)
b_sheet.Cells(i2 + 9, I + 1) = (High(I) - Low(I)) / 2
b_sheet.Cells(X1 + 10, I + 1) = Fo(I)
b_sheet.Cells(X1 + 11, I + 1) = Keep(I)
b_sheet.Cells(i2 + 4, 10) = "最大差值:"
b_sheet.Cells(i2 + 4, 14) = cha1
b_sheet.Cells(X1 + 13, 11) = "测试日期:"
b_sheet.Cells(X1 + 13, 12) = "2009年01月01日"
Next '打印表尾
UserForm1.Hide '隐藏窗口
End Sub
我也不懂VBA
[其他解释]
楼上太给力了。注意身体
[其他解释]