If 语句跳过内部代码

If statement skipping internal code

首先,此代码处于保密协议之下,我无法展示更多。 我想让一颗星星以黑色或黄色出现在 sheet 上。当代码通过 sheet 选择时,它会跳回主代码。我已经尝试了另一种 if then 和当前的 Case 格式。无论它应该查看的单元格中有什么,代码都会跳过。我把数字,真,假。整个程序都是基于查找表,我只是想为星星添加代码。任何帮助都会很棒。

  Sub Star()

  Range(Cells(nxtRow, "B"), Cells(nxtRow + 1, "B")).Select
  With Selection
    .MergeCells = True
  End With

   '8.3x11 sheet
    If (p_size = 1) Then
      y = 171.25 + 43.5 * Mtimes
        ActiveSheet.Shapes.AddShape(msoShape5pointStar, 23.25, y, 22, 
        _22).Select
     Select Case Cells(i, "s").Value

    'chooses yellow

        Case True
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

    'chooses black

        Case False
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 1
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

        Case Else: MsgBox ("star color indeterminate")
        End Select


'11x17 sheet
    ElseIf (p_size = 2) Then
     y = 160 + 33 * Mtimes
    ActiveSheet.Shapes.AddShape(msoShape5pointStar, 48#, y, 22, 22).Select

    Select Case Cells(i, "s").Value

    'chooses yellow

        Case True
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

    'chooses black

        Case False
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 1
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

        Case Else: MsgBox ("star color indeterminate")
        End Select

    End If

End Sub

最终固定代码。在 Wookiee 的帮助下,我得到了正确的颜色。所以,我制作了 'i' 一个收集的变量,并修复了跳过。我添加了 worksheet ('d") 通过查看正确的位置来为星星正确着色。

  Sub Star(i)

  Range(Cells(nxtRow, "B"), Cells(nxtRow + 1, "B")).Select
With Selection
    .MergeCells = True
  End With

'8.3x11 sheet
  If (p_size = 1) Then
    y = 171.25 + 43.5 * Mtimes
    ActiveSheet.Shapes.AddShape(msoShape5pointStar, 23.25, y, 
22, 22).Select
    Select Case Sheets("d").Cells(i, "s").Value

    'chooses yellow

        Case True
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 
 255, 255)

    'chooses black

        Case False
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 0
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

        Case Else: MsgBox ("star color not found")
        End Select


'11x17 sheet
ElseIf (p_size = 2) Then
    y = 160 + 33 * Mtimes
    ActiveSheet.Shapes.AddShape(msoShape5pointStar, 48#, y, 
  22, 22).Select

    Select Case Sheets("d").Cells(i, "s").Value

    'chooses yellow

        Case True
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 13
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 
  255, 255)

    'chooses black

        Case False
            Selection.ShapeRange.Fill.Visible = msoTrue
            Selection.ShapeRange.Fill.Solid
            Selection.ShapeRange.Fill.ForeColor.SchemeColor = 0
            Selection.ShapeRange.Fill.Transparency = 0#
            Selection.ShapeRange.Line.Weight = 0.75
            Selection.ShapeRange.Line.DashStyle = msoLineSolid
            Selection.ShapeRange.Line.Style = msoLineSingle
            Selection.ShapeRange.Line.Transparency = 0#
            Selection.ShapeRange.Line.Visible = msoTrue
            Selection.ShapeRange.Line.ForeColor.SchemeColor = 64
            Selection.ShapeRange.Line.BackColor.RGB = RGB(255, 255, 255)

        Case Else: MsgBox ("star color not found")
        End Select
     Else: MsgBox ("paper size not found")
    End If

End Sub

检查两行中 "i" 变量的值:

Select Case Cells(i, "s").Value

可能不在您期望的范围内。