|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 验收记录()
Dim ar As Variant
Dim br()
Dim r As Long
Dim cellDate As Date
Dim i As Long
With Sheets("收入")
r = .Cells(Rows.Count, 2).End(xlUp).Row
If r < 2 Then MsgBox "表为空!": End
ar = .Range("a1:t" & r)
End With
With Sheets("验收记录")
cellDate = .Range("K3").Value
If cellDate = 0 Then MsgBox "请输入日期!": End
ReDim br(1 To UBound(ar), 1 To 12)
For i = 2 To UBound(ar)
If ar(i, 20) = cellDate Then
n = n + 1
br(n, 1) = n
br(n, 2) = Split(ar(i, 4), " ", 2)(0) ' 第一个空格前的内容
br(n, 4) = Split(ar(i, 4), " ", 2)(1) ' 第一个空格后的内容
br(n, 5) = ar(i, 5)
br(n, 8) = ar(i, 11)
End If
Next i
If n = "" Then MsgBox "收入表中没有" & cellDate & "的数据!": End
rs = .Cells(Rows.Count, 1).End(xlUp).Row - 6
If rs >= 9 Then
.Rows("9:" & rs).Delete
End If
.Rows("9:" & 9 + n - 1).Insert Shift:=xlDown
For i = 9 To 9 + n - 1
.Cells(i, 2).Resize(1, 2).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Selection.Merge
.Cells(i, 8).Resize(1, 2).Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlCenter
End With
Selection.Merge
Next i
.[a9].Resize(n, UBound(br, 2)) = br
.[a8].Resize(n + 1, UBound(br, 2)).Borders.LineStyle = 1
With .Rows("9:" & n + 9 - 1)
.Font.Name = "宋体"
.Font.Size = 11
.RowHeight = 35
.WrapText = True
End With
'.Cells.EntireRow.AutoFit '自动行高'
End With
MsgBox "ok!"
End Sub
|
|