【发布时间】:2019-02-11 15:37:01
【问题描述】:
我有一个工作簿,其中有一个主工作表和其余工作表。基本上,我的代码所做的是循环遍历未命名为“Main”的工作簿中的工作表并提取值并将它们放入主工作表中的适当列中。 IsError 检查 Sheetname 是否已存在于列表中,如果存在 - 它不会添加值。 工作表的布局非常混乱,有许多合并的单元格 - https://imgur.com/cayZXUA。
因此,在每张工作表中(主要工作表除外),我都有包含“工资单”、“综合社会税”和“杂项支出”值的块。我想出了在每张工作表中给这些块命名为“假设”的想法,并且我为每张工作表设定了范围,以便可以在所有工作表中重复“假设”并且我可以遍历它。这是这个区块的图片 - https://imgur.com/nPYyLbM。
代码运行但我得到#VALUE!我的主工作表上的错误 - https://imgur.com/a/H2TOFmW 抱歉链接,还没有发布图片的权限
这是代码本身:
Sub Sheets()
Dim wsheet As Worksheet
With ThisWorkbook.Sheets("Main")
For Each wsheet In ThisWorkbook.Sheets
If wsheet.Name <> "Main" Then
Set nextEntry = .Cells(.Rows.Count, "G").End(xlUp).Offset(1, 0)
Set nextEntry_payroll = .Cells(.Rows.Count, "AI").End(xlUp).Offset(1, 0)
Set nextEntry_consolidated_social_tax = .Cells(.Rows.Count, "AJ").End(xlUp).Offset(1, 0)
Set nextEntry_miscellaneous_expenditures = .Cells(.Rows.Count, "AK").End(xlUp).Offset(1, 0)
If IsError(Application.Match(wsheet.Name, .Range("G:G"), 0)) Then
nextEntry.Value = wsheet.Name
nextEntry_payroll.Value = wsheet.Application.VLookup("payroll", "Assumptions", 3, 0)
nextEntry_consolidated_social_tax.Value = wsheet.Application.VLookup("consolidated social tax", "Assumptions", 3, 0)
nextEntry_miscellaneous_expenditures.Value = wsheet.Application.VLookup("miscellaneous expenditures", "Assumptions", 3, 0)
End If
End If
Debug.Print wsheet.Name
Next wsheet
End Sub
【问题讨论】:
-
你知道错误在哪一行吗?
-
它没有给我错误,它运行。这只是它在主工作表中给我的值“#VALUE!”
-
单步调试您的代码并找出哪一行错误。