Microsoft Excel输出总计为具有多个单元格的新工作表 [英] Microsoft Excel Output total to new sheet with multiple cells
问题描述
如何更改留言板的输出以将其输出到新工作表
How do I change the output from a message board to have it output on to a new sheet
'输出总计到消息框
sTtl ="总库存数量" &安培; dStk& " =" &安培; TotStk
sMsg =" Board No." &安培; vbTab& "Cut Lenght" &安培; vbCrLf
对于k = LBound(DetStk,2)To UBound(DetStk,2)
sMsg = sMsg& DetStk(0,k)& vbTab& vbTab _
&安培; DetStk(1,k)& vbCrLf
下一个k
MsgBox sMsg,vbOKOnly,sTtl
'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
推荐答案
您好
Lwhetham,
从上面的代码我可以理解你想要将结果添加到工作表而不是显示msgbox。
from your code above I can understand that you want to add the result to worksheet instead of displaying msgbox.
你可以尝试创建一个对象表格,然后尝试找到列中的最后一个单元格并在那里添加数据。
you can try to create a object of sheet and then try to find the last cell in the column and add the data there.
如下所示。
Sub demo()
Dim sht As Worksheet
Dim LastRow As Long
Dim sTtl As String
sTtl = "Total stock at Shop = 100"
Set sht = ThisWorkbook.Worksheets("Sheet1")
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1
sht.Cells(LastRow, 1).Value = sTtl
End Sub
所以数据将被添加到工作表中,如下所示。
so the data will be added to the sheet like below.
您可以将代码修改为根据你的要求。
you can modify the code as per your requirement.
插入如下的多个单元格。
to insert in a multiple cell like below.
Sub demo()
Dim sht As Worksheet
Dim LastRow As Long
Dim sTtl, bno, cl As String
sTtl = "Total stock at Shop = 100"
bno = "Board No = 50"
cl = "cut length = 10"
Set sht = ThisWorkbook.Worksheets("Sheet1")
LastRow = sht.Cells(sht.Rows.Count, "A").End(xlUp).Row + 1
sht.Cells(LastRow, 1).Value = sTtl
sht.Cells(LastRow, 2).Value = bno
sht.Cells(LastRow, 3).Value = cl
End Sub
输出:
问候
Deepak
这篇关于Microsoft Excel输出总计为具有多个单元格的新工作表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!