|
按照你的报表样式,利用VBA实现了点击就自动导入数据的功能。运行有点慢,要点时间。但是什么低于最小值,高于最大值实在没看明白,是和什么比较。
但是你的报表样式实在比较奇怪,没有按照EXCEL每列独立的字段,来设计表格。所以EXCEL自带的数据选取分析功能,根本就没办法用。建议以后设计报表的时候,考虑这个问题
VBA
Sub SelectFile()
Dim FileName As Variant, xlRange As Range, sWKName As String, i As Integer, Hang As Integer, j As Integer
FileName = Application.GetOpenFilename("Excel 文件 (*.xls),*.xls", , , , 0)
If FileName = False Then Exit Sub
Workbooks.Open FileName
sWKName = Application.ActiveWorkbook.Name
On Error Resume Next
Set xlRange = Application.InputBox("请选取单元格", , , , , , , 8)
If xlRange Is Nothing Then GoTo 100
xlRange.Copy Destination:=ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(269, 4)
Hang = xlRange.Rows.Count
Application.ScreenUpdating = False
ThisWorkbook.Sheets("RWT_PD0 (2)").Range("G269:K1000").Copy Destination:=ThisWorkbook.Sheets("RWT_PD0 (2)").Range("D269")
ThisWorkbook.Sheets("RWT_PD0 (2)").Range("L269:V1000").Copy Destination:=ThisWorkbook.Sheets("RWT_PD0 (2)").Range("K269")
ThisWorkbook.Sheets("RWT_PD0 (2)").Range("I269:J1000").Clear
ThisWorkbook.Sheets("RWT_PD0 (2)").Range("V269:V1000").Clear
For i = 270 To (268 + Hang * 2) Step 2
ThisWorkbook.Sheets("RWT_PD0 (2)").Rows(i).Insert
ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(i, 10).Value = "(A)-(SPEC.)"
For j = 11 To 21
ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(i, j) = ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(i - 1, j) - ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(2, j)
Next j
ThisWorkbook.Sheets("RWT_PD0 (2)").Range(ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(i, 10), ThisWorkbook.Sheets("RWT_PD0 (2)").Cells(i, 21)).Interior.ColorIndex = 15
Next i
100:
Workbooks(sWKName).Close False
Application.ScreenUpdating = True
End Sub |
|