|
- 这是一个 VBA 的,不知道是不是楼主想要的。
-
- Sub saixuan()
- Dim Sh As Worksheet, arr(), i As Long, n As Integer, c As Integer
- Set Sh = Sheets("1#-土建")
- With Range("A4:Z65536")
- .ClearContents
- .Borders.LineStyle = xlNone
- End With
- If Not IsDate(Range("C1")) Then
- Range("C1:D1").Interior.ColorIndex = 3
- MsgBox "请在红色区域输入日期!"
- Exit Sub
- End If
- Range("C1:D1").Interior.ColorIndex = xlNone
- For c = 13 To 256
- If Format(Sh.Cells(1, c), "yyyymm") = Format(Range("C1"), "yyyymm") Then
- Exit For
- End If
- Next
- If c > 256 Then MsgBox "没有找到 " & Format(Range("C1"), "yyyymm") & " 的记录!": Exit Sub
- For i = 4 To Sh.Range("A65536").End(3).Row
- If Sh.Cells(i, c + 1) > 0 Then
- n = n + 1
- ReDim Preserve arr(1 To 7, 1 To n)
- arr(1, n) = Sh.Range("A" & i) '序号
- arr(2, n) = Sh.Range("B" & i) '项目编码
- arr(3, n) = Sh.Range("C" & i) '项目名称
- arr(4, n) = Sh.Range("E" & i) '单位
- arr(5, n) = Sh.Cells(i, c + 1) '清单量
- arr(6, n) = Sh.Range("L" & i) '综合单价
- arr(7, n) = arr(5, n) * arr(6, n) '合价
- End If
- Next
- With Range("A4").Resize(UBound(arr, 2), 7)
- .Value = WorksheetFunction.Transpose(arr)
- .Borders.LineStyle = xlContinuous
- End With
- Set Sh = Nothing
- End Sub
复制代码
|
|