VBA – dynamic更改公式

我有一个下拉validationformuala单元格,并在validation中使用vba中的通用公式。

现在,我想使用with循环中的formula1部分来自动化它。

这里是守则,

Lastrow = ActiveSheet.Cells(Rows.Count, "A").End(xlUp).Row Lastrow2 = Sheets("Config").Cells(Rows.Count, "R").End(xlUp).Row For i = 2 To Lastrow With Range("M" & i).Validation .Delete .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _ Operator:=xlBetween, Formula1:="=Config!R2:R10" .IgnoreBlank = True .InCellDropdown = True .InputTitle = "" .ErrorTitle = "" .InputMessage = "" .ErrorMessage = "" .ShowInput = True .ShowError = True End With Next 

你将如何replace代码中的部分 – Formula1:=“= Config!R2:R10”,其中10为Lastrow2。

谢谢

解决scheme :

 Formula1:="=Config!R2:R"&Lastrow2