我正在将符合条件的行从一张纸复制到另一张纸。我在for循环中设置了一堆布尔语句,以使我的if语句更整洁,因为我将做几个elseif。我的if语句中出现类型不匹配错误。有什么想法吗?
VBA代码:
Dim blActive As Boolean
Dim blSeason1 As Boolean
Dim blSeason2 As Boolean
Dim blSeason3 As Boolean
Dim blSeason4 As Boolean
Dim blSeason5 As Boolean
Dim blSeason6 As Boolean
Dim blNA As Boolean
Dim blInter As Boolean
Dim blGlobal As Boolean
Dim blDrop As Boolean
Dim blSMUDrop As Boolean
Dim blPromoDrop As Boolean
Dim blPromoNBR As Boolean
Dim blUSWS As Boolean
Dim blUSMSRP As Boolean
Dim blCanWS As Boolean
Dim blCanMSRP As Boolean
Dim blFOB As Boolean
For i = 2 To lRow_Spec
'Check if Forecast Season = "ACTIVE",
blActive = (Worksheets("Item_Spec_Data").Cells(i, 1).Value = "ACTIVE")
'Check for All 6 seasons Seasons(based on "Buy Ready missing info Seasons"
blSeason1 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 2).Value)
blSeason2 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 3).Value)
blSeason3 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 4).Value)
blSeason4 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 5).Value)
blSeason5 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 6).Value)
blSeason6 = (Worksheets("Item_Spec_Data").Cells(i, 2).Value = Worksheets(mySheet).Cells(35, 7).Value)
'Check which Distribution it is (NA, Global,International) Have to break this out b/c each area has different blank checks
blNA = (Worksheets("Item_Spec_Data").Cells(i, 5).Value = Worksheets(mySheet).Cells(24, 9).Value)
blInter = (Worksheets("Item_Spec_Data").Cells(i, 5).Value = Worksheets(mySheet).Cells(24, 11).Value)
blGlobal = (Worksheets("Item_Spec_Data").Cells(i, 5).Value = Worksheets(mySheet).Cells(24, 13).Value)
'Checking that status is not irrelevant
blDrop = (Worksheets("Item_Spec_Data").Cells(i, 3).Value = "Drop")
blSMUDrop = (Worksheets("Item_Spec_Data").Cells(i, 3).Value = "SMU Drop")
blPromoDrop = (Worksheets("Item_Spec_Data").Cells(i, 3).Value = "Promo Drop")
blPromoNBR = (Worksheets("Item_Spec_Data").Cells(i, 3).Value = "Promo-NBR")
'Checking for Blanks US WS, US MSRP, Can WS, Can MSRP, FOB
blUSWS = (Worksheets("Item_Spec_Data").Cells(i, 22).Value = " ")
blUSMSRP = (Worksheets("Item_Spec_Data").Cells(i, 23).Value = " ")
blCanWS = (Worksheets("Item_Spec_Data").Cells(i, 24).Value = " ")
blCanMSRP = (Worksheets("Item_Spec_Data").Cells(i, 25).Value = " ")
blFOB = (Worksheets("Item_Spec_Data").Cells(i, 26).Value = " ")
If blActive & _
blNA & _
(blSeason1 Or blSeason2 Or blSeason3 Or blSeason4 Or blSeason5 Or blSeason6) & _
blDrop & blSMUDrop & blPromoDrop & blPromoNBR & _
(blUSWS Or blUSMSRP Or blFOB) _
Then
答案 0 :(得分:0)
您使用逻辑AND而不是&进行字符串连接。
If blActive AND _
blNA AND _
(blSeason1 Or blSeason2 Or blSeason3 Or blSeason4 Or blSeason5 Or blSeason6) AND _
blDrop AND blSMUDrop AND blPromoDrop AND blPromoNBR AND _
(blUSWS Or blUSMSRP Or blFOB) _
Then