|
楼主 |
发表于 2024-10-26 22:50
|
显示全部楼层
已解决问题:
Private Sub CommandButton2_Click()
Dim rng As Range
Dim r%, iRowMax%
Application.ScreenUpdating = False
Application.EnableEvents = False
' 清除 [C9:G20] 区域的内容
Sheets("报告明细").Range("C9:G20").ClearContents
With Sheets("报告明细")
iRowMax = .Cells(Rows.Count, "G").End(3).Row
Set rng = .Range("G:G").Find([l2], , , 1)
If rng Is Nothing Then
MsgBox "没有此车牌号。 ", 48, "查询销售单"
Exit Sub
End If
r = rng.Row
' 构建要赋值到合并单元格的字符串
Dim data(1 To 5)
data(1) = "检测次数:3"
data(2) = "1):" & .Cells(r, "T").Value
data(3) = "2):" & .Cells(r, "U").Value
data(4) = "3):" & .Cells(r, "V").Value
data(5) = "平均值:" & .Cells(r, "W").Value
Dim mergedData As String
For i = 1 To 5
mergedData = mergedData & data(i) & Chr(10)
Next i
' 先取消可能存在的合并,再进行合并并赋值
Range("E18:G22").UnMerge
Range("E18:G22").Merge
Range("E18:G22").Value = mergedData
Range("E18:G22").WrapText = True
' 以下是其他单元格的赋值
[C4] = Cells(r, "M")
[C5] = Cells(r, "H")
[I5] = Cells(r, "I")
[C6] = Cells(r, "K")
[I6] = Cells(r, "P")
[C7] = Cells(r, "AE")
[I7] = Cells(r, "AF")
[C8] = Cells(r, "AG")
[I8] = Cells(r, "AH")
[I9] = Cells(r, "S")
[C11] = Cells(r, "D")
[I11] = Cells(r, "AI")
[C12] = Cells(r, "AJ")
[I12] = Cells(r, "R")
[B19] = Cells(r, "AK")
[B22] = Cells(r, "AL")
[I18] = Cells(r, "G")
[I4] = Cells(r, "G")
[J24] = Cells(r, "AD")
[A3] = "报告编号:" & Cells(r, "AC")
End With
Application.EnableEvents = True
Application.ScreenUpdating = True
End Sub
|
|