仅将数据validation从一个表中的单个行复制到另一个表的所有行

只想将工作表TEMPLATE(Maint。)中名为Table1_1的表中的数据validation复制到名为TEMPLATE的另一个工作表上的表中。 我已经看了可用的主题,但没有一个非常接近我正在寻找的东西。

其中一个问题是这些表格中的任何一个表格可能最终都会移位,所以当我构build这个macros时,我将需要考虑到这一点。

到目前为止我所拥有的是:

  1. 复制工作表TEMPLATE(维护 )中Table1_1的第一个(也是唯一一行
  2. 查看工作表TEMPLATE中的单元格A3并获取它所属的表。
  3. find步骤2中find的表的第一行。
  4. 粘贴第一行表格中所有列的数据validation。
  5. 对表的所有行重复步骤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 

我创build了一个图表,展示了我的每个Excel VBA模块的目标。 请记住,这可能不包括所有的细节,我第一部分工作。 显示子使用顺序的图表

Excel VBA联机帮助包含您完成此操作所需的一切。 只需validation对象成员的帮助页面就足够了。

下面的例程将从一个单元复制validation到另一个。 你应该可以在双循环中调用它(对于目标行和列)。 一旦你完成了testing,这可能应该是一个Privatefunction

 Sub CopyValidation(ByRef rngSourceCell As Range, ByRef rngTargetCell As Range) With rngTargetCell.Validation .Delete .Add Type:=rngSourceCell.Validation.Type, _ AlertStyle:=rngSourceCell.Validation.AlertStyle, _ Operator:=rngSourceCell.Validation.Operator, Formula1:=rngSourceCell.Validation.Formula1, Formula2:=rngSourceCell.Validation.Formula2 .ErrorMessage = rngSourceCell.Validation.ErrorMessage .ErrorTitle = rngSourceCell.Validation.ErrorTitle .IgnoreBlank = rngSourceCell.Validation.IgnoreBlank .IMEMode = rngSourceCell.Validation.IMEMode .InCellDropdown = rngSourceCell.Validation.InCellDropdown .InputMessage = rngSourceCell.Validation.InputMessage .InputTitle = rngSourceCell.Validation.InputTitle .ShowError = rngSourceCell.Validation.ShowError .ShowInput = rngSourceCell.Validation.ShowInput End With End Sub