0

我正在尝试为多个条件和选择场景做一个 vba 代码。AR 列是我想显示选择结果的列。我的选择逻辑是:

If Column E (cells(m,5)) equals "Not IBC", then put value in the cell in AR (cells(m,44)) as "Exclude"
If Column AQ (cells(m,43)) equals "Yes", then put value in the cell in AR (cells(m,44)) as "Exclude"
If Column W (cells(m,23)) equals "X" or "Y", then put value in the cell in AR (cells(m,44)) as "Exclude"
If Column G (cells(m,7)) equals "A" or "B" or "C" and Column I (cells(m,9)) is not equal to "1.1" nor "1.2", then put value in the cell in AR (cells(m,44)) as "Exclude"
Rest would give AR as Include

我的实际代码是

但是,即使我将单元格类型更改为常规,我也会收到类型不匹配错误。

有没有办法消除类型不匹配错误,或者我的代码是否基于逻辑是正确的?

谢谢!

Sub inclusion()

Columns("AR:AR").Insert Shift:=xlToRight, _
      CopyOrigin:=xlFormatFromLeftOrAbove
      Columns("AR:AR").Cells(1, 1) = "Include?"

Application.ScreenUpdating = False
With Range("G:G")  '
        .NumberFormat = "General"
        .Value = .Value
        .NumberFormat = "0"
End With
Application.ScreenUpdating = True

With Range("I:I")  '
        .NumberFormat = "General"
        .Value = .Value
        .NumberFormat = "0"
End With
Application.ScreenUpdating = True

Dim lastRow4 As Long
    lastRow4 = Range("K" & Rows.Count).End(xlUp).Row

Dim legacy As String
Dim tax As String
Dim inclusion As String
Dim IBC As String
Dim pact As String
Dim agg As String

Dim m As Long
For m = 2 To lastRow4

legacy = Cells(m, 7)
tax = Cells(m, 9)
IBC = Cells(m, 5)
pact = Cells(m, 23)
agg = Cells(m, 43)


Select Case True

Case IBC = "Not IBC"
inclusion = "Exclude"

Case agg = "Yes"
inclusion = "Exclude"

Case (pact = "X" Or Impact = "Y")
inclusion = "Exclude"

Case (legacy = "A" Or legacy = "B" Or legacy = "C") And tax <> "1.1" And tax <> "1.2"
                inclusion = "Exclude"
Case Else
inclusion = "Include"

Cells(m, 44) = inclusion
End Select

Next m

End Sub
4

0 回答 0