" DATA"我有2个表格: 首先是2列 - 区域和区域,在第2列中 - 区域(这与表1中的区域相同但没有重复)。此表是从其他数据创建的。 在Sheet" NEW"我需要在一个单元格验证列表中列出区域(来自表2),在下面的单元格中我需要具有Territory的验证列表,但仅限于上面单元格中的选定区域。 我做了这个代码:
With wb.Sheets("DATA")
.ListObjects.Add(xlSrcRange, .Range("E1").CurrentRegion, , xlYes).Name = "Table1"
.Sort.SortFields.Add Key:=Range("E1"), _
SortOn:=xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
end with
wb.Names.Add Name:="dd_primary", RefersToR1C1:="=tbl_primary[Area Name]"
With wb.Sheets("NEW").Range("C8").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=dd_primary"
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
With wb.Sheets("DATA")
.Select
.ListObjects.Add(xlSrcRange, .Range("A1").CurrentRegion, , xlYes).Name = "Table2"
.ListObjects("Table2").Name = "tbl_secondary"
.Sort.SortFields.Add Key:=Range("tbl_secondary[[#All],[Area Name]]"), SortOn:= _
xlSortOnValues, Order:=xlAscending, DataOption:=xlSortTextAsNumbers
.Sort.Apply
End With
wb.Sheets("NEW").Select
wb.Names.Add Name:="dd_ttyy", RefersToR1C1:= _
"=INDEX(tbl_secondary[Territory Name],MATCH('NEW SR'!R8C3,tbl_secondary[Area Name],0),1): INDEX(tbl_secondary[Territory Name],MATCH('NEW SR'!R8C3,tbl_secondary[Area Name],1),1)"
With wb.Sheets("NEW").Range("C9").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=dd_ttyy"
.IgnoreBlank = True
.InCellDropdown = True
.ShowInput = True
.ShowError = True
End With
我在尝试加载新数据时遇到错误1004:应用程序定义或对象定义错误。你能帮忙解决这个问题吗? 谢谢