【发布时间】:2016-03-24 18:36:40
【问题描述】:
我只想将数据验证从工作表 TEMPLATE (Maint.) 上名为 Table1_1 的表中复制到另一个名为 的工作表上的表中模板。我已经查看了可用的主题,但没有一个与我正在寻找的主题非常接近。
其中一个问题是这些工作表中的任何一张上的表格最终可能会移动,因此当我构建此宏时,我需要考虑到这一点。
到目前为止,我拥有的是:
- 复制工作表 TEMPLATE (Maint.) 上 Table1_1 的第一行(也是唯一一行)。
- 查看工作表 TEMPLATE 上的单元格 A3 并获取它所属的表格。
- 找到在步骤 2 中找到的表格的第一行。
- 将表格中所有列的数据验证粘贴到第一行。
- 对表格的所有行重复步骤 3 和 4。
我目前的代码:
Dim TotalSheets As Integer
Dim p As Integer
Dim iAnswer As VbMsgBoxResult
' This Dim is supposed to be to add worksheets, for the process _
' of copying the data validations to the new sheets, to a skip _
' list. An array perhaps? Skip any sheets listed in this array?
Dim DNCToShts As ?
' The cell to get the table that it is apart of for copying from _
' the other worksheet, "TEMPLATE (Maint.)"
Dim GetCellsTable_Copy As String
' The cell to get the table that it is apart of for pasting onto _
' the other worksheets.
Dim GetCellsTable_Paste As String
' This is the cell to reference on "TEMPLATE (Maint.)" worksheet _
' to get the table name of, this will always be "Table1_1"
GetCellsTable_Copy = "A3"
' This is the cell to reference on each sheet to get the table name.
GetCellsTable_Paste = "A3"
With Aplication
.DisplayAlerts = False
.ScreenUpdating = False
End With
iAnswer = MsgBox("You are about to copy data validations! Do you _
want to proceed?", vbOKCancel + vbExclamation _
+ vbDefaultButton2 + vbMsgBoxSetForeground + vbApplicationModal, _
"Copying Data Valadations")
' Instead of copying the whole table I just need to copy the first row _
' of data, intending to copy just the data validations portion.
Range("Table1_1").Copy
If iAnswer = vbYes Then
p = 1 To Sheets.Count
If UCase$(Sheets(p).Name) <> DNCToShts
StoreTableName = Range(GetCellsTable_Paste).ListObject.Name
我已经创建了一个图表,显示了我的每个 Excel VBA 模块的目标。请记住,这可能不包括所有细节,我正在处理仅第 1 部分。:
【问题讨论】:
-
请发布您的部分或全部代码以供参考
-
@TheGuyThatDoesntKnowMuch 我已经添加了我已经积累的代码。有什么你可以收集到的或者有什么需要进一步解释的吗?
-
除了上面粘贴的内容之外,我基本上没有写太多代码。 :-/