已经阅读了其他一些有1004错误和引用问题的问题。我试图将它应用于我的代码,但我仍然有这个错误。当我首先激活工作表并选择range_list
时,它可以工作,但我想避免这种情况。错误在.Add
Set tableau_scores = wsParam.Range(wsParam.Cells(3, 1), wsParam.Cells(derniere_ligne_scores, 1))
For i = 0 To nombre_sousclasse_actif(numero_actif - 1, 0) - 1
Set range_liste = wsScores.Range(wsScores.Cells(derniere_ligne + 1, 2 + i), wsScores.Cells(derniere_ligne + 1, 2 + i))
With range_liste.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="='" & wsParam.Name & "'!" & tableau_scores.Address
End With
range_liste.Value = 0
Next i
谢谢!
编辑:当我在工作表上时它会起作用" Param"但不在表格上,而是分数"
编辑2:我真的不明白,我创建了一个新模块,我把这个代码运行起来......
Sub testliste()
Dim tableau_scores As Range
Dim range_liste As Range
Set tableau_scores = ThisWorkbook.Worksheets("Param").Range(ThisWorkbook.Worksheets("Param").Cells(3, 1), ThisWorkbook.Worksheets("Param").Cells(7, 1))
Set range_liste = ThisWorkbook.Worksheets("Scores").Range(ThisWorkbook.Worksheets("Scores").Cells(9, 2), ThisWorkbook.Worksheets("Scores").Cells(9, 2))
With range_liste.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:="='" & ThisWorkbook.Worksheets("Param").Name & "'!" & tableau_scores.Address
End With
range_liste.Value = 0
End Sub