Excel VBA: Get Results for Multiple Cells

I am trying to get the result from different cells based on the given if expression. I get the result in several message boxes, and the result for all cells is calculated based on checking the first statement. How can I get all the results in one msgbox and allow the function to check every single cell in a range?

 Dim rcell As Range For Each rcell In Vou_Summary.Range("I5:I16") If 0 < rcell <= 2.5 Then MsgBox rcell.Cells.Offset(0, -3).Value & " Is Critical", vbOKOnly, "Notice!" ElseIf 2.5 < rcell <= 4 Then MsgBox rcell.Cells.Offset(0, -3).Value & " Requires PR Placement", vbOKOnly, "Notice!" ElseIf rcell >= 7 Then MsgBox rcell.Cells.Offset(0, -3).Value & " Is Oversupplied", vbOKOnly, "Notice!" Else End If Next 
+5
source share
1 answer

You can create a string variable first. Do not drop MsgBox, but store the results in a variable. In the past, the End If statement shows MsgBox and passes the string variable as content.

Better, you can use String Builder to make it work about 1000 times faster than VBA concatenation by default;)

+3
source

Source: https://habr.com/ru/post/1207216/


All Articles