将长嵌套if和or公式转换为vba大小写

时间:2016-10-21 15:18:41

标签: excel vba excel-vba if-statement nested

我有一个嵌套的int bigIcon = Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP ? R.drawable.logo_who_is_not_white: R.drawable.logo_who_is_in_whit_tint; 公式,我试图将其转换为使用VBA的If And Or公式(或任何其他建议会很棒),但我是初学者而不确定如何。原因是此公式目前位于每个单元Case中,占用的内存太多,电子表格速度极慢。

基本上,我尝试将列AG12:ACG500(停电月开始)中的日期与行Z12:Z500(日期)中的日期相匹配,然后查看列AG6:ACG6(ACTV_NAME) ...在两个日期(列Z和行6)相交的单元格中提供C12:C500的输出..这应该与甘特图栏开始的位置一致..我不需要任何帮助使用甘特图表条/颜色编码..我只需要帮助基本上用前面提到的标记它们。

R, S, L, MR, MS, ML, ?R, ?S or ?L

2 个答案:

答案 0 :(得分:0)

您的公式可以简化为:

=IF(OR($Z12="",$AA12=""),"",IF(AND(AG$6=$Z12,$Z12<>""),IF($L12 = "YES","M" & LEFT($C12,1),IF($L12 = "Maybe","?" & LEFT($C12,1),LEFT($C12,1))),""))

答案 1 :(得分:0)

将单个公式转换为循环

的例程

这是Scott Craner的公式的简化版本,转换为循环遍历AG12:ACG500中所有单元格的例程,并检查每个单元格的交叉标准。

我无法测试此代码,因为我没有基于它的数据集。话虽如此,我不确定它会以你想要的方式表现。如果它适合您,请告诉我。

Sub compareDates()
    Dim ws As Worksheet: Set ws = ThisWorkbook.Sheets(1)
    Dim dataRange As Range: Set dataRange = ws.Range("AG12:ACG500")
    Dim oMS As Range, aN As Range, idk As Range, d As Range
    Dim yNM As Range, myCell As Range, myRow As Long, myCol As Long

    For Each myCell In dataRange
        myRow = myCell.Row
        myCol = myCell.Column

        Set oMS = ws.Range("Z" & myRow)  'Outage Month Start
        Set aN = ws.Range("C" & myRow)   'ACTV_NAME
        Set idk = ws.Range("AA" & myRow) 'not sure what AA is for
        Set d = ws.Cells(6, myCol)  'DATES
        Set yNM = ws.Range("L" & myRow)  'yes no maybe

        If oMS.Value = "" Or idk.Value = "" Then
            myCell.Value = ""
        ElseIf d.Value = oMS.Value And oMS.Value <> "" Then
            If UCase(yNM.Value) = UCase("Yes") Then
                myCell.Value = "M" & Left(aN.Value, 1)
            ElseIf UCase(yNM.Value) = UCase("Maybe") Then
                myCell.Value = "?" & Left(aN.Value, 1)
            Else: myCell.Value = Left(aN.Value, 1)
            End If
        Else: myCell.Value = ""
        End If
    Next myCell
End Sub