Excelmacros将数据validation只从工作表复制到其他几个工作表

我正在使用Excel,并希望根据单元格地址(例如A3)获取表格的名称,此单元格不会移动。 我如何去在Excel的VBA中说明这一点?

我的计划是让代码将数据validation从“维护”选项卡上的一行表中的一行复制到工作簿(减去“TOC”和“数据”选项卡)每个选项卡上的单个表中。 每个选项卡都是“TEMPLATE”工作表的副本(减去“TOC”,“data”和“TEMPLATE(Maint。)”工作表)。 工作表“数据”,“模板”和“模板(维护)”可能隐藏,也可能不隐藏。

编辑:我想去做这个:

  1. 在“模板(维护)”工作表上复制数据validation
  2. 在目标工作表上检查C3,并查找它分开的表格; 单元格C3是最左上angular的单元格,它是一个标题
  3. 将数据validation复制到步骤2中find的表中的每个数据行。
  4. 重复步骤2和3,直到所有工作表都将validation复制到(减去“TOC”,“data”和“TEMPLATE(Maint。)”工作表)。

我在“Copy_Data_Validations”子文件中的代码如下所示:

Dim TotalSheets As Integer Dim p As Integer Dim iAnswer As VbMsgBoxResult With Application .DisplayAlerts = False .ScreenUpdating = False End With ' ' Move sheet "TOC" to the begining of the workbook. ' Sheets("TOC").Move Before:=Sheets(1) ' ' Move sheet "data" to be the second sheet in the workbook. ' Sheets("data").Move Before:=Sheets(2) iAnswer = MsgBox("You are about to copy data validations!", vbOKCancel + vbExclamation _ + vbDefaultButton2 + vbMsgBoxSetForeground, "Copying Data Valadations") For TotalSheets = 1 To Sheets.Count For p = 3 To Sheets.Count - 2 ' ' If the answer is Yes, then copy data validations from "TEMPLATE (Maint.) to all other. ' sheets minus the "TOC" sheet and the "data" sheet. ' If iAnswer = vbYes Then If UCase$(Sheets(p).Name) <> "TOC" And UCase$(Sheets(p).Name) <> "data" Then ' This chunk of code should copy only the data validations ' of "Table1_1" (A4:AO4) from the maintenance tab to all ' rows of a single table on each worksheet (minus the ' "TOC", "data", & the "TEMPLATE (Maint.)" worksheets. ' This is the section of code I am looking for unless ' someone has something better they can come up with. Selection.PasteSpecial Paste:=xlPasteValidation, _ Operation:=xlNone, SkipBlanks:=False, Transpose:=False End If ' ' If the answer is Cancel, then cancels. ' ElseIf iAnswer = vbCancel Then ' Add an exit here. End If With Application .DisplayAlerts = True .ScreenUpdating = True End With 

 Sub test() Dim ws As Worksheet With Application .DisplayAlerts = False .ScreenUpdating = False End With For Each ws In ThisWorkbook.Worksheets If ws.Name <> "TOI" And ws.Name <> "DATA" And ws.Name <> "TEMPLATE (Maint.)" Then Sheets("TEMPLATE (Maint.)").Select Range("Table1").Select Selection.Copy ws.Select Range("A1").Select Selection.PasteSpecial Paste:=xlPasteValidation, Operation:=xlNone, _ SkipBlanks:=False, Transpose:=False End If Next With Application .DisplayAlerts = True .ScreenUpdating = True End With End Sub