|
工作簿加载另外一个工作簿数据后,运行红框的命令程序会出错,替换成数字后没问题,忘大神指点迷津
C1.zip
(991.13 KB, 下载次数: 11)
Sub t()
Dim rg As Range
Dim wb1, wb2 As Workbook
Dim pth, x, y, z As Variant
Dim i, m, n As Integer
pth = Application.GetOpenFilename()
If pth = False Then
GoTo Myend
End If
Set wb1 = ThisWorkbook
Set wb2 = Workbooks.Open(pth)
n = 2
For m = 3 To wb2.Sheets.Count
wb2.Sheets(m).Select
For Each rg In wb2.Sheets(m).Range("aj5:cu5")
If rg.Value = "DATA 1" Then
i = rg.Column
x = 4
'x = Right(wb2.Sheets(m).Cells(4, i), Len(wb2.Sheets(m).Cells(4, i)) - Len("After HWT Shelf"))'开启这条命令程序就出错
For i = i To i + 5
wb1.Sheets("KV").Range("Q" & n) = WorksheetFunction.Average(wb2.Sheets(m).Range(Cells(46, i), Cells(306, i)))
wb1.Sheets("KV").Range("Q" & n).NumberFormatLocal = "0.000"
wb1.Sheets("KV").Range("R" & n) = WorksheetFunction.Max(wb2.Sheets(m).Range(Cells(46, i), Cells(306, i)))
wb1.Sheets("KV").Range("Q" & n).NumberFormatLocal = "0.000"
wb1.Sheets("KV").Range("P" & n) = "VIS"
wb1.Sheets("KV").Range("Q" & n + 1) = WorksheetFunction.Average(wb2.Sheets(m).Range(Cells(306, i), Cells(406, i)))
wb1.Sheets("KV").Range("Q" & n + 1).NumberFormatLocal = "0.000"
wb1.Sheets("KV").Range("R" & n + 1) = WorksheetFunction.Max(wb2.Sheets(m).Range(Cells(306, i), Cells(406, i)))
wb1.Sheets("KV").Range("R" & n + 1).NumberFormatLocal = "0.000"
wb1.Sheets("KV").Range("P" & n + 1) = "NIR"
wb1.Sheets("KV").Range("M" & n) = x
wb1.Sheets("KV").Range("M" & n + 1) = x
n = n + 2
Next
End If
Next
Next
wb2.Close savechanges:=False
Myend:
End Sub
|
|