总计显示在消息框中,我希望它们在excel中的新工作表上。
'Output totals to a message box
sTtl = "Total stock at " & dStk & " = " & TotStk
sMsg = "Board No." & vbTab & "Cut Lenght" & vbCrLf
For k = LBound(DetStk, 2) To UBound(DetStk, 2)
sMsg = sMsg & DetStk(0, k) & vbTab & vbTab _
& DetStk(1, k) & vbCrLf
Next k
MsgBox sMsg, vbOKOnly, sTtl
End Sub
答案 0 :(得分:0)
下面的代码将创建一个新工作表,并将为消息框生成的数据(包括标题和标题)插入到2列中。如果不再希望它出现,您可以注释掉或删除消息框行msgbox sMsg, .....
。
'Output totals to a message box
Sheets.Add After:=Sheets(Sheets.Count) ' create a new sheet
sTtl = "Total stock at " & dStk & " = " & TotStk
Range("A1").value = sTtl 'put th title in cell A1
sMsg = "Board No." & vbTab & "Cut Lenght" & vbCrLf
Range("A2").value = "Board No."
Range("B2").value = "Cut Lenght"
Range("A2:B2").Font.Bold = True ' format the headings bold (optional)
intRow = 3 ' set starting row below the heading row.
For k = LBound(DetStk, 2) To UBound(DetStk, 2)
sMsg = sMsg & DetStk(0, k) & vbTab & vbTab _
& DetStk(1, k) & vbCrLf
Range("A"&intRow).value = DetStk(0, k)
Range("B"&intRow).value = DetStk(1, k)
intRow = intRow + 1 'add 1 to move to the next row.
Next k
MsgBox sMsg, vbOKOnly, sTtl 'you can delete this line or comment it out with "'" if you don't want to display the message box.
End Sub