1.怎样选择某列有数值的全部?
Dim rng As Range Set rng=Range([C2],Cells(Rows.Count,"C").End(xlUp)) For Each cell In rng ... Next cell
Sub 遍历某列活动的单元格() Dim rng As Range Dim i As Integer i = 0 Set rng = Range([A1], Cells(Rows.Count, "A").End(xlUp)) For Each cell In rng i = i + 1 Next cell MsgBox i End Sub
VBA计算混合料孔隙比:
1 Sub 计算混合料孔隙比() 2 ‘st_Date = Sheets("表1").Range("I2").Value 3 Dim e1 As Double, e2 As Double, theta As Double, f As Double 4 Sheets("sheet1").Range("a1") = "f" 5 Sheets("sheet1").Range("B1") = "e1" 6 Sheets("sheet1").Range("C1") = "e2" 7 Sheets("sheet1").Range("D1") = "theta2low" 8 Sheets("sheet1").Range("F1") = "f1" 9 Sheets("sheet1").Range("G1") = "f2" 10 Sheets("sheet1").Range("H1") = "f3" 11 Sheets("sheet1").Range("I1") = "f4" 12 Sheets("sheet1").Range("J1") = "f5" 13 Sheets("sheet1").Range("K1") = "f6" 14 Sheets("sheet1").Range("L1") = "f7" 15 Sheets("sheet1").Range("M1") = "f8" 16 Sheets("sheet1").Range("N1") = "f9" 17 18 Dim i As Integer, j As Integer 19 ‘给定初始值 20 For i = 2 To 10 21 Sheet1.Cells(i, 1) = "f" & i - 1 22 If i < 10 / 2 + 1 Then 23 Sheet1.Cells(i, 2) = 0.2 * (i - 1) ‘e1 24 Sheet1.Cells(i, 3) = 1 ‘e2 25 Else 26 Sheet1.Cells(i, 2) = 1 27 Sheet1.Cells(i, 3) = 1 - (i - 6) * 0.2 28 End If 29 Sheet1.Cells(i, 4) = (Cells(i, 2) + Cells(i, 2) * Cells(i, 3)) / (Cells(i, 2) + Cells(i, 3) + 2 * Cells(i, 2) * Cells(i, 3)) 30 Next i 31 Cells(1, 5) = "theta" ‘石头所占体积比 32 For i = 2 To 1002 33 Cells(i, 5) = 0 + 0.001 * (i - 2) 34 For j = 1 To 9 35 If Cells(i, 5) < Cells(j + 1, 4) Then 36 Cells(i, j + 5) = Cells(j + 1, 2) * (1 - Cells(i, 5)) / (Cells(i, 5) * Cells(j + 1, 2) + 1) 37 Else 38 Cells(i, j + 5) = Cells(i, 5) * Cells(j + 1, 3) / (1 + Cells(j + 1, 3) * (1 - Cells(i, 5))) 39 End If 40 Next j 41 Next i 42 43 End Sub
时间: 2024-11-05 16:07:45