iT邦幫忙

0

VBA合併縮減內容

  • 分享至 

  • xImage

分兩段是因為不曉得如何讓 1 To 10 執行完成,才跳出訊息視窗,請求縮減內容謝謝

Sub Test()
For aq = 1 To 10
        If Cells(aq, 1) > 1 Then
            Cells(aq, 1).Interior.Color = RGB(255, 255, 0)
        End If
Next

For aq = 1 To 10
        If Cells(aq, 1).Interior.Color = RGB(255, 255, 0) Then
            MsgBox "超過數量"
            End
        End If
Next
End Sub
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

2 個回答

1
rogeryao
iT邦超人 8 級 ‧ 2021-05-05 06:51:43
最佳解答
Sub Test()
Dim u As Integer
u = 0
For aq = 1 To 10
  If Cells(aq, 1) > 1 Then
      Cells(aq, 1).Interior.Color = RGB(255, 255, 0)
      u = 1
  End If
Next

If u > 0 Then
    MsgBox "超過數量"
End If
End Sub

非常感謝,你的回答對我很有幫助

0
blanksoul12
iT邦研究生 5 級 ‧ 2021-05-05 11:09:06

For aq = 1 To 10
If Cells(aq, 1) > 1 Then
Cells(aq, 1).Interior.Color = RGB(255, 255, 0)
End If
Next
MsgBox "超過數量"

小魚 iT邦大師 1 級 ‧ 2021-05-05 12:38:19 檢舉

你沒有判斷啊..

blanksoul12 iT邦研究生 5 級 ‧ 2021-05-05 14:53:42 檢舉

行完 for next 跳出後 aq 已經大過10

沒有判斷是指,即使數值沒有大於1,還是會跳出超過數量的訊息視窗
還是很感謝你的回答

我要發表回答

立即登入回答