将公式转换为vba

我有一个表评估。 在表格中,我必须寻找三列S,T和U.

如果列S包含无效,并且如果列T和U都填满了,那么我需要筛选整行。

为此,我尝试了下面的代码。 代码对我来说工作正常。 但是对于我的其他同事来说,这个filter根据条件不起作用。

列Z被视为帮助者列,根据条件标记为真或假。 如果T和U两列都填满了,S是无效的,那么就表示为假,其余为真

我已经使用了所有模块的选项。

任何人都可以build议,我怎么能克服这个? 任何人都可以帮助我编码,而不使用公式

Sub fc() Dim totalrows As Long Dim sformula totalrows = Range("A5").End(xlDown).Row With Sheets("Evaluation").Range("Z5:Z" & totalrows) ' if the S5 is not equal to invalid and any one of the column T and U are filled, then activate autofilter sformula = "=AND(S5<>""Invalid"",OR(ISBLANK(T5),ISBLANK(U5)))" .Formula = sformula .AutoFilter 26, True .Value = .Value End With End Sub 

我只是试了一下,根据我在那里的经验,下面应该可以工作:

 Sub fc() Dim totalrows As Long, sformula AS String sformula = "=AND(S5<>""Invalid"",OR(ISBLANK(T5),ISBLANK(U5)))" totalrows = Range("A5").End(xlDown).Row With Sheets("Evaluation").Range("Z5:Z" & totalrows) .Formula = sformula .AutoFilter 1, True ' take the first column of the current range End With End Sub 

在你的版本中,你使用了.AutoFilter 26, True 工作,你是否已经将它应用到范围[a1:z<no of rows>] ,但是由于你正在处理范围[z1:z<no of rows>]你只有一列在你的范围内。

我也不知道你想用.value = .value达到什么目的。 据我所知,这只会用当前值取代当前值,也就是说什么也没有用,或者我错过了什么?

 Sub fc() Dim totalrows As Long, sformula As String totalrows = Range("A5").End(xlDown).Row sformula = "=AND(S5<>""Invalid"",OR(ISBLANK(T5),ISBLANK(U5)))" Application.ScreenUpdating = False With Sheets("Evaluation").Range("Z5:Z" & totalrows) .Formula = sformula .Calculate DoEvents .Value = .Value .AutoFilter 26, True End With Application.ScreenUpdating = True End Sub