Excel 一鍵判斷(VBA版,附全部代碼)

VBA?什麼是VBA?VBA做什麼的?……

不懂,沒關係,照著做就行了。

首先,我們準備一張數據表,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

接下來,我們按組合鍵:【Alt】+【F11】,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

然後,我們選擇【插入】→【模塊】,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

接下來,我們在空白處,輸入如下代碼(效果圖,如下圖):

Sub 判斷成績等級()

Dim h%

h = 2

Do While Cells(h, 2) <> ""

If Cells(h, 2) >= 90 Then

Cells(h, 3) = "優秀"

ElseIf Cells(h, 2) < 90 And Cells(h, 2) >= 70 Then

Cells(h, 3) = "良好"

ElseIf Cells(h, 2) < 70 And Cells(h, 2) >= 60 Then

Cells(h, 3) = "及格"

Else

Cells(h, 3) = "不及格"

End If

h = h + 1

Loop

End Sub

Excel 一鍵判斷(VBA版,附全部代碼)

接下來,我們再按一次組合鍵:【Alt】+【F11】,切換回Excel界面,同時插入一個圖形,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

Excel 一鍵判斷(VBA版,附全部代碼)

備註一下:畫啥圖形,這個隨意,沒有強制要求。

接下來,我們右擊剛才畫的圖形,點擊【指定宏】,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

我們在彈出的指定宏的窗口中,選中【判斷成績等級】,然後點擊【確定】,如下圖:

Excel 一鍵判斷(VBA版,附全部代碼)

然後我們點擊,剛才畫的圖形,就發現,成績等級,自動標註了哦(效果圖如下)

Excel 一鍵判斷(VBA版,附全部代碼)

喜歡我的作品的話,請關注一下。謝謝


分享到:


相關文章: