Show all 0 value cells in a MsgBox

Kigiin

New Member
Joined
Sep 23, 2016
Messages
3
Hi!

I would like to write a macro that shows all cells address (or row) which value is 0 in column 10.

So far i only could manage this:

Sub check()
Dim LastRow As Long




LastRow = Cells(Rows.Count, 1).End(xlUp).Row


For i = 2 To LastRow
If Cells(i, 10).Value = 0 Then
MsgBox ("0 value in" & Cells(i, 10).Address & "cell)
End If

Next i


End Sub

But my problem is, that it shows a lot of separate msgbox, but I would like only one, which contains all the addresses.

Thank you for your help!
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Code:
Sub check()
 
 Dim LastRow As Long, i As Long
Dim Zero_Value As String
 LastRow = Cells(Rows.Count, 1).End(xlUp).Row

 For i = 2 To LastRow
    If Cells(i, 10).Value = 0 Then Zero_Value = Zero_Value & Cells(i, 10).Address & ", "
Next i
 
 Zero_Value = Left(Zero_Value, Len(Zero_Value) - 2)
 
 MsgBox "0 value in " & Zero_Value
 
 End Sub
 
Upvote 0
Code:
Sub check()
 
 Dim LastRow As Long, i As Long
Dim Zero_Value As String
 LastRow = Cells(Rows.Count, 1).End(xlUp).Row

 For i = 2 To LastRow
    If Cells(i, 10).Value = 0 Then Zero_Value = Zero_Value & Cells(i, 10).Address & ", "
Next i
 
 Zero_Value = Left(Zero_Value, Len(Zero_Value) - 2)
 
 MsgBox "0 value in " & Zero_Value
 
 End Sub


Thank you so much for your help!
But i have one last question. If there is no cell with 0 value in collumn 10 then this code get run-time error.
How could I expand this code that in this case the msgbox says "that everything is fine"?
 
Upvote 0
I find a way! I added only 2 lines:
OnError GoTo Error_handler

Error_handler:
MsgBox "there is no 0 value"
 
Upvote 0

Forum statistics

Threads
1,216,759
Messages
6,132,556
Members
449,735
Latest member
Gary_M

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top