简体   繁体   English

Excel VBA,找到一个范围的行数并将其应用于另一个范围的末尾

[英]Excel VBA, finding the row count of a range and applying it to the end of another range

I'm working through a VBA project in Excel (2010 but running in xml, not xmls) and I'm having some troubles. 我正在通过Excel中的VBA项目(2010,但以xml而非xmls运行),但遇到了一些麻烦。 In short, I'm running a =IF((OR(NOT(ISERR(SEARCH....etc in a cell to the very far right of the sheet. Then, I need to xlfilldown, but I need the range to be dynamic. The rows that the IF statement is searching varies from tab to tab, and there is data below it (separated with 1-2 blank rows!) which may contain the same strings i'm searching for, but would provide the wrong data. 简而言之,我正在表格的最右边的单元格中运行= IF((OR(NOT(ISERR(SEARCH .... etc.etc等等)。然后,我需要xlfilldown,但我需要将范围IF语句正在搜索的行随选项卡的不同而不同,并且它下面有数据(用1-2个空白行分隔!),这些数据可能包含我正在搜索的相同字符串,但会提供错误的数据。

So, is it possible to track the row number of the endpoint of the column in the data being IF((OR(NOT(ISERR(SEARCH and then apply that column number as the endpoint of another range, so that the xlfilldown only goes as far as the table? And if so, how would this be done? 因此,是否有可能在数据为IF((OR(NOT(ISERR(SEARCH))的情况下跟踪列的端点的行号,然后将该列号应用为另一个范围的端点,因此xlfilldown仅作为到桌子旁边,如果可以的话,该怎么办?

Thanks all!! 谢谢大家!

Range("IF2").Select ActiveCell.Formula = _ "=IF((OR(NOT(ISERR(SEARCH("" perf "",A24))),NOT(ISERR(SEARCH("" profi "",A24))),NOT(ISERR(SEARCH("" commu "",A24))),NOT(ISERR(SEARCH("" equip "",A24))),NOT(ISERR(SEARCH("" occu "",A24))),NOT(ISERR(SEARCH("" emplo "",A24))),NOT(ISERR(SEARCH("" liqu "",A24))),NOT(ISERR(SEARCH("" withholding "",A24))),NOT(ISERR(SEARCH("" ince "",A24))),NOT(ISERR(SEARCH("" trust "",A24))),NOT(ISERR(SEARCH("" mana "", A24))),NOT(ISERR(SEARCH("" mgmt "", A24))),NOT(ISERR(SEARCH("" incentive "", A24)))))=TRUE, C24, 0)" Range(“ IF2”)。Select ActiveCell.Formula = _“ = IF((OR(NOT(ISERR(SEARCH(”“ perf ”“,A24))),NOT(ISERR(SEARCH(”“ profi ”“,A24 ))),NOT(ISERR(SEARCH(“” commu “”,A24))),NOT(ISERR(SEARCH(“” equip “”,A24))),NOT(ISERR(SEARCH(“” occu “”, A24))),NOT(ISERR(SEARCH(“” emplo “”,A24))),NOT(ISERR(SEARCH(“” liqu “”,A24))),NOT(ISERR(SEARCH(“” 扣缴 “” ,A24))),NOT(ISERR(SEARCH(“” ince “”,A24))))NOT(ISERR(SEARCH(“” trust “”,A24))),NOT(ISERR(SEARCH(“” mana “ “,A24))),NOT(ISERR(SEARCH(”“ mgmt ”“,A24))))NOT(ISERR(SEARCH(”“ 激励 ”“,A24))))))))= TRUE,C24,0)”

I need this to fill-down until the last cell containing anything in A, any ideas? 我需要填写直到最后一个单元格中包含A中的任何内容,有什么想法吗?

Your formula can be reduced to something like 您的公式可以简化为

=IF(SUM(IFERROR(SEARCH(words,A24),0))>0,C24, 0)

entered as an array formula (Ctrl+Shift+Enter), where words is a named range with the words to search for. 输入为数组公式(Ctrl + Shift + Enter),其中words是带有搜索words的命名范围。 You might find that easier to maintain. 您可能会发现它更易于维护。

Dim f As Range
With ActiveSheet
    Set f = .Cells(Rows.Count, 1).End(xlUp)
    If f.Row >= 24 Then 
        .Range("B24").FormulaArray = _
                "=IF(SUM(IFERROR(SEARCH(words,A24),0))>0,C24, 0)"
        .Range("B24:B" & f.Row).FillDown
    End If
End With

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

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