我有一个excel工作簿,其范围是动态的。我想找到这个动态范围的最大值。这是我的代码块,我试图找到最大值
Set SearchRng1 = Cells(2, 2)
Debug.Print SearchRng1.Address
Set SearchRng2 = Cells(LastRow, j + 2)
Debug.Print SearchRng2.Address
With hidden3ws
Worksheets("Hidden3").Activate
Range("B2").Formula = "=ROUNDUP(MAX('Incre_Calc_A'!SearchRng1:SearchRng2),-1)"
End With
但是输出的是= #NAME? 有人可以帮我这个代码,所以我可以得到一个实际的价值?提前谢谢!
答案 0 :(得分:2)
您需要从字符串中删除变量并连接:
Set SearchRng1 = Cells(2, 2)
Debug.Print SearchRng1.Address
Set SearchRng2 = Cells(LastRow, j + 2)
Debug.Print SearchRng2.Address
With hidden3ws
Worksheets("Hidden3").Activate
Range("B2").Formula = "=ROUNDUP(MAX('Incre_Calc_A'!" & SearchRng1.Address & ":" & SearchRng2.Address & "),-1)"
End With