我正在使用Excel,并希望根据单元格地址(例如A3)获取表格的名称,该单元格不会移动。我该如何在Excel的VBA中陈述此问题?
我的计划是编写代码,将一个表格上的数据验证复制到工作簿每个标签页上的单个表格中(除了我的“TOC”和“data”标签)。每个标签页都是“TEMPLATE”工作表的副本(除了“TOC”,“data”和“TEMPLATE(Maint.)”工作表)。工作表“data”,“TEMPLATE”和“TEMPLATE(Maint.)”可能已隐藏。
我“Copy_Data_Validations”子程序中的代码如下:
我的计划是编写代码,将一个表格上的数据验证复制到工作簿每个标签页上的单个表格中(除了我的“TOC”和“data”标签)。每个标签页都是“TEMPLATE”工作表的副本(除了“TOC”,“data”和“TEMPLATE(Maint.)”工作表)。工作表“data”,“TEMPLATE”和“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