|
楼主 |
发表于 2024-3-25 17:15
|
显示全部楼层
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
求助大师,我思路有点混乱,如下代码,仅为参考,不灵活,没能完全实现,等待大师帮助
Sub ConnectData()
Dim i As Integer
Dim salesDept As String
Dim customer As String
Dim fruitTotal As Double
Dim vegTotal As Double
Dim result As String
For i = 5 To 9
salesDept = Cells(i, 1).Value
customer = Cells(i, 2).Value
nam = Cells(i, 3).Value
' fruitTotal = Cells(i, 3).Value + Cells(i, 4).Value + Cells(i, 5).Value
fruitTotal = Cells(i, 4).Value + Cells(i, 5).Value + Cells(i, 6).Value
vegTotal = Cells(i, 6).Value + Cells(i, 7).Value + Cells(i, 8).Value
result = salesDept & "、" & customer & ":给客户 " & nam & " 售出共 " & fruitTotal & "kg, 水果 " & fruitTotal & "kg (" & Cells(i, 3).Value & "kg, " & Cells(i, 4).Value & "kg, " & Cells(i, 5).Value & "kg)。"
If vegTotal > 0 Then
result = result & " 蔬菜 " & vegTotal & "kg (" & Cells(i, 6).Value & "kg, " & Cells(i, 7).Value & "kg, " & Cells(i, 8).Value & "kg)。"
End If
Cells(i, 12).Value = result
Next i
End Sub |
|