0

我需要帮助将函数转换为 VBA 代码,有人可以帮助我吗?

这是功能:

=IF(H4&I4&J4="TEXT"&"TEXT"&"TEXT";"TEXT";
IF(J4&I4="TEXT"&"TEXT";H4;
IF(H4&J4="TEXT"&"TEXT";I4;
IF(H4&I4="TEXT"&"TEXT";J4;
IF(J4="TEXT";(H4+I4)/2;IF(I4="TEXT";(H4+J4)/2;
IF(H4="TEXT";(I4+J4)/2;(H4+I4+J4)/3))))))

我试图在 VBA 中写这样的东西,但是没有用。. . . . . . .

If Cells(H4) and Cells (I4) and Cells (J4) = "TEXT". Then 
4

1 回答 1

0

我无法理解公式。你想做什么?

关于比较您拥有的单元格文本,请像这样使用 VBA 代码

Range("H4").Value = "TEXT"

所以If Cells(H4) and Cells (I4) and Cells (J4) = "TEXT" Then变成

If Range("H4").Value = "TEXT" And _
Range("I4").Value = "TEXT" And _
Range("J4").Value = "TEXT" Then
    '~~> Do Something
End If

上面的代码也可以写成

Dim strString As String

strString = Range("H4").Value & Range("I4").Value & Range("J4").Value

If strString = "TEXTTEXTTEXT" Then
    '~~> Do Something
End If
于 2013-04-21T11:30:55.230 回答