VBA:定义范围内的variables而不是单元格名称

我有一个名为“select名称”的单元格,它随机放置在同一工作簿的很多表单中。 请我想知道如何在工作簿的所有工作簿中查找单元格值。我尝试了循环遍历所有工作表和第一行的所有单元格查找该string值,但我似乎无法find解决scheme,这是我做的:

For Each ws In ActiveWorkbook.Worksheets col_num = ws.Range("A1").End(xlToRight).Column For Cel1 = 1 To clom_num If ws.Cells(1, Cel1).Value = "Cell Name" Then col_name = ws.Cells(2, Cel1).Name End If Next With ws.Range("col_name:col_name").Validation ' Here when i put ("L:L") it works, but that value can be in any cell .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _ xlBetween, Formula1:=Liste .IgnoreBlank = True .InCellDropdown = True End With 

哦,我得到这个错误就行了(与ws.Range(“col_name:col_name”)。validation)“对象_worksheet的方法范围失败”

请帮助

而不是循环,使用Range.Find方法:

  Dim ws As Worksheet Dim rngFound As Range For Each ws In ActiveWorkbook.Sheets Set rngFound = ws.Rows(1).Find("Cell Name", , xlValues, xlWhole) If Not rngFound Is Nothing Then With ws.Columns(rngFound.Column).Validation .Delete .Add xlValidateList, xlValidAlertStop, xlBetween, Liste .IgnoreBlank = True .InCellDropdown = True End With End If Next ws