|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
Public Sub CommandButton1_Click()
On Error GoTo Errorhandler
Dim tex As String
Dim name As String
Dim pag As Byte
name = TextBox1.Text
tex = ThisWorkbook.Path & "\" & name '获取气路图文件路径
Workbooks.Open (tex)
Errorhandler:
If Err.Description <> "" Then
MsgBox "请将气路图名称复制到文本框中并检查名称是否正确!"
End If
ActiveWorkbook.Sheets.Item(1).Activate '激活第一个工作表
'Range("L2") = Val(Range("L2"))
'Range("E2") = Val(Range("E2")) '将该列文本格式转化为数字格式
pag = ActiveSheet.PageSetup.Pages.Count '计算表格共有多少页
Dim y As Long
Dim x As Long
Dim z As Long
For x = 1 To pag
If x = pag Then
y = Cells.Find("*", LookIn:=xlFormulas, searchdirection:=xlPrevious).Row
Else
y = ActiveSheet.HPageBreaks(x).Location.Row - 1
End If
Dim a As Long
Dim b As Long
a = y - 39
b = y - 20
z = Application.Sum(Sheets.Item(1).Range("L" & a & ":L" & b)) '计算右侧L列的阀门数量
Dim e As Long
Dim f As Long
e = y - 39
f = y - 1
Range("E" & e & ":E" & f).Value = Range("E" & e & ":E" & f).Value * z
|
|