【发布时间】:2017-09-10 15:04:27
【问题描述】:
我是新手,正在学习 Excel VBA。我现在遇到了这个问题
- 一个工作表中的表超过10个(表数不一致)
- 列数一致但各表行数不一致
- 我想在每个表的末尾应用一个总行
- 之后,我会将相同的公式应用于每个表格,并将结果放在每个表格的右侧
这可能很容易,但核心问题是范围未知。 - 由于它不是 Excel 中的实际表格,所以我尝试首先通过为其创建表格来定义数据的范围,然后再次,我不知道如何在不知道范围的情况下创建表格。
下面是我想出的东西(不是很“动态”)
Sub plsWork()
Set u = ThisWorkbook.Worksheets("Sheet2")
Set f = u.Range("A").Find(what:="Name", lookat:=xlPart)
a = f.Address
Set sht = u.Range(a)
'trying to insert this at the end of the table
Total = Sum(u.Offset(2, 1) + u.Offset(3, 1) + u.Offset(4, 1))
If Cells(i, 2) = vbNullString Then 'this is already not applicable as the top 2 row in colB has null string
u.Offset(i, 1).Value = Total
'putting the table name at F2
u.Offset(-2, 5).Value = u.Offset(-3, 0).Value
u.Offset(-2, 6).Value = Total
u.Offset(-1, 5).Value = u.Offset(2, 0).Value
u.Offset(-1, 6).Value = Sum(u.Offset(2, 1) + u.Offset(2, 2) + u.Offset(2, 3))
u.Offset(0, 5).Value = u.Offset(3, 0).Value
u.Offset(0, 6).Value = Sum(u.Offset(3, 1) + u.Offset(3, 2) + u.Offset(3, 3))
u.Offset(1, 5).Value = u.Offset(4, 0).Value
u.Offset(1, 6).Value = Sum(u.Offset(4, 1) + u.Offset(4, 2) + u.Offset(4, 3))
End Sub
哦,当我运行上面的代码时,“SUM”上出现错误“Sub or Function not defined”
Here is the image of the tables in a sheet
黄色突出显示的是执行子后将出现的内容。
在 Excel 工作表中应用公式并将公式复制粘贴到每个表格非常容易,
但这很乏味,所以我尝试提供一个 vba 代码来提供帮助,以便宏可以按计划运行。
这两天我一直在摸索着来回寻找,
我仍然不知道如何编码。
那么有专家可以告诉我这是否可能吗?喜欢不知道范围?
如果是这样,你们能否告诉我一些关于如何实现这一目标的信息?
谢谢你。我真的很想知道这是否可以做到。
【问题讨论】:
标签: vba excel excel-formula