简体   繁体   English

如何使用捕获地址的动态变量来放置VBA公式?

[英]How to put a VBA formula using dynamic variables capturing Address?

I am running a Loop to capture the start of Range and end of Range for a particular scenario. 我正在运行一个循环,以捕获特定情况下Range的起点和终点。 After I find my start range and end range, I want to put it as a formula in a cell. 找到起始范围和终止范围后,我想将其作为公式放入单元格中。 For example: 例如:

Cells(1,1).Formula  "= Min( startrange:endrange)"

The above code has assumed the variables as text and instead of putting the cell address these variables are handling, it is pasting the formula as text like this : '= Min( startrange:endrange)' 上面的代码假定变量为文本,而不是将这些变量处理的单元格地址放置为文本,而是将公式粘贴为文本:'= Min(startrange:endrange)'

I have no idea and have tried different approaches I could get from internet like below 我不知道,并且尝试了如下几种可以从互联网上获得的方法

'    cells(4,4).formula = "=Min("&startrage& :"" & endrange & ")""
'      Cells(4, 4).Formula = "=Min(startrange.value :endrange)"

'Cells(4, 4).Formula = Application.WorksheetFunction.Min(startrange:endrange)
 '   Cells(4, 4).Formula =  "=Min("&startrange&"&":"& " &endrange&")"

where 哪里

 startrange = ActiveCell.Offset(1, 3).Address(0, 0)
endrange = ActiveCell.Offset(0, 3).Address(0, 0)

Nothing works. 什么都没有。

How can I achieve this? 我该如何实现? Specially I am also facing error in handling ":". 特别是我在处理“:”时也遇到错误。

cells(4,4).formula = "=Min(" & startrage & ":" & endrange & ")"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM