Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
String 范围作为字符串,用公式填充单元格_String_Vba_Excel_Excel Formula - Fatal编程技术网

String 范围作为字符串,用公式填充单元格

String 范围作为字符串,用公式填充单元格,string,vba,excel,excel-formula,String,Vba,Excel,Excel Formula,背景:我正在处理的项目计划Excel有不同的类别和不同数量的项目。我已经编写了一个宏,它将生成类别,类别之间有必要的行数 目标:在创建类别的循环中,用公式(见图)填充单元格,公式的范围将根据行的数量而变化 循环如下所示: For i = 1 To RowCounter 'The offset is used to copy the next category and not the first each time, the counter will make sure it mov

背景:我正在处理的项目计划Excel有不同的类别和不同数量的项目。我已经编写了一个宏,它将生成类别,类别之间有必要的行数

目标:在创建类别的循环中,用公式(见图)填充单元格,公式的范围将根据行的数量而变化

循环如下所示:

 For i = 1 To RowCounter
     'The offset is used to copy the next category and not the first each time, the counter will make sure it moves the appropriate amount of positions
    Set rng = cate.Range("A1").Offset(CateCount, 0)
    rng.Copy

    'for this one we tell where it should paste the value. For every new loop it needs to move more cells downward, which is why we use the CateCount 3
    Set rng2 = times.Range("B11").Offset(CateCount2, 0)
    rng2.PasteSpecial

    'The CateCount3 will count how many rows we need to add by counting how many times the category we are dealing with now
    'defined by rng there is in the action sheet and then adding 1 one

    CateCount3 = Application.CountIf(Worksheets("All actions Sheet").Range("B:B"), rng)

    'Here we group the layers
    Set rng = Range(rng2.Offset(1, 0), rng2.Offset(CateCount3, 0))
    rng.Rows.Group

    'Create the numbers of the categories using a loop
    Dim CatNum As Integer
    Set rng = cate.Range("A1", cate.Range("A1").Offset(RowCounter, 1))

    CatNum = Application.WorksheetFunction.VLookup(rng2.value, rng, 2, True)
    Dim NumCount As Integer
    NumCount = 0

    For j = 0 To CateCount3
        Set rng = rng2.Offset(NumCount, -1)
        rng = CatNum + NumCount
        NumCount = NumCount + 1
    Next j

    'We need to add one unit to the counter so that for the next loop it will start one category below
    CateCount = CateCount + 1
    'The CateCount2 is used to add the right number of rows for the next loop
    CateCount2 = CateCount2 + CateCount3 + 1
    'We need to "delete" the contents of CateCount3 after every loop
    CateCount3 = 0

Next i
我已经可以使用VBA中的公式来计算它了

Set rng = rng2.Offset(0, 1)
Set rng3 = Range(rng2.Offset(1, 1), rng2.Offset(CateCount3, 1))
rng = Application.Min(rng3)
但是,我希望公式保留在单元格中,因为表格可以随时更改,并且我不希望总是必须更新宏

问题:
如何将VBA公式转换为保留在单元格中的字符串?您可以这样做,而不是
application.min(rng2.offset…to simply=min(C12:C17)

rng.Formula = "=MIN(" & rng3.Address & ")"

你可以这样做:

rng.Formula = "=MIN(" & rng3.Address & ")"

你可以这样做:

rng.Formula = "=MIN(" & rng3.Address & ")"

你可以这样做:

rng.Formula = "=MIN(" & rng3.Address & ")"

您也可以完全跳过rng3变量的需要

rng.formulua = "=Min(" & Range(rng2.Offset(1, 1), rng2.Offset(CateCount3, 1)).address & ")"

您也可以完全跳过rng3变量的需要

rng.formulua = "=Min(" & Range(rng2.Offset(1, 1), rng2.Offset(CateCount3, 1)).address & ")"

您也可以完全跳过rng3变量的需要

rng.formulua = "=Min(" & Range(rng2.Offset(1, 1), rng2.Offset(CateCount3, 1)).address & ")"

您也可以完全跳过rng3变量的需要

rng.formulua = "=Min(" & Range(rng2.Offset(1, 1), rng2.Offset(CateCount3, 1)).address & ")"

哦,太棒了!我不知道.address(我只是个初学者)。谢谢!!哦,太棒了!我不知道.address(我只是个初学者)。谢谢!!哦,太棒了!我不知道.address(我只是个初学者)。谢谢!!哦,太棒了!我不知道.address(我只是个初学者)。我不知道.address(我只是个初学者)谢谢!!