Sub Ex()
Dim Ar(), E As Range, Msg$, i%, y%, C%
Ar = Array("a2", "g2", "a8", "g8")
C = 4
For i = 1 To Sheet1.[C2:F6].Columns.Count
Msg = ""
y = 0
For Each E In [C2:F6].Columns(i).Cells
If E <> "" Then
Msg = IIf(Msg <> "", Msg & Chr(10), "") & "在" & Cells(E.Row, 1) & "店買了" & Cells(E.Row, 2) & E & "枝"
y = y + 1
End If
Next
Sheet2.Range(Ar(i - 1)) = IIf(Msg <> "", Msg & Application.Rept(Chr(10), IIf(y < C, C - y, 0)) & IIf(y < C, "請至A店取貨", ""), "")
Next
For i = 1 To Sheet1.[C7:F11].Columns.Count
Msg = ""
y = 0
For Each E In [C7:F11].Columns(i).Cells
If E <> "" Then
Msg = IIf(Msg <> "", Msg & Chr(10), "") & "在" & Cells(E.Row, 1) & "店買了" & Cells(E.Row, 2) & E & "枝"
y = y + 1
End If
Next
Sheet2.Range(Ar(i - 1)) = IIf(Msg <> "", Msg & Application.Rept(Chr(10), IIf(y < C, C - y, 0)) & IIf(y < C, "請至B店取貨", ""), "")
Next
End Sub作者: GBKEE 時間: 2010-8-17 11:31