Excel-宏与VBA-if-select

学习视频,本文是观看前视频时做的笔记,手动感谢up🐖。

if

  1. if else 基本使用案例
Sub ifTest()
  Dim score As Integer
  score = 80
  if score >= 60 Then
    MsgBox "Pass"
  Else
    MsgBox "No Pass"
  End If
End Sub
  1. if elseIf 基本使用案例
Sub ifTest()
  Dim score As Integer
  score = 80
  if score >= 60 Then
    MsgBox "Pass"
  ElseIf score >= 50 
    MsgBox "No Pass"
  ElseIf score >= 40 
    MsgBox "No Pass"
  ElseIf score >= 30 
    MsgBox "No Pass"
  Else
    MsgBox "No Pass"
  End If
End Sub

select case

  1. 基本使用案例
Sub selectTest()
  Dim score As Integer
  score = 80
  
  Select Case score
    Case Is >= 90
      MsgBox "优秀"
    Case Is >= 80
      MsgBox "中上"
    Case Is >= 60
      MsgBox "及格"
    Case Else
      MsgBox "不及格"
  End Select
End Sub
posted @ 2021-05-12 16:38  乔悟空  阅读(238)  评论(0编辑  收藏  举报