Error checking - Dim i as Integer

Billdub417

New Member
Joined
Nov 5, 2019
Messages
45
Hello, I have the following code to check that each cell = 0. There are 12 cells, for each month of the year and I was trying to make it flag up which periods did not equal zero. However, this code will only show "Period1". Thanks in advance

Code:
With Sheet22
        Dim i As Integer
        i = 1
        For Each cell In .Range("v3:v14").Cells
            If cell.value <> 0 Then
                MsgBox ("Period" & i & " does not balance")
                Sheets("Mapping").Select
                Exit Sub
            End If
        Next
        
     End With
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.
A) You are not incrementing i at each iteration
B) you are telling it to Exit the sub after it finds 1 cell not = 0

Code:
With Sheet22
        Dim i As Integer
        i = 1
        For Each cell In .Range("v3:v14").Cells
            If cell.value <> 0 Then
                MsgBox ("Period" & i & " does not balance") 
                'Exit Sub
            End If
        i = i + 1 
        Next
        Sheets("Mapping").Select
End With
 
Upvote 0
Solution
You said:
I was trying to make it flag up

What does flag up mean?

If you want the Msgbox to Popup what do you want it to say?
Your post seems to just want the same Message each time.


 
Upvote 0
This works perfectly, thanks!

A) You are not incrementing i at each iteration
B) you are telling it to Exit the sub after it finds 1 cell not = 0

Code:
With Sheet22
        Dim i As Integer
        i = 1
        For Each cell In .Range("v3:v14").Cells
            If cell.value <> 0 Then
                MsgBox ("Period" & i & " does not balance") 
                'Exit Sub
            End If
        i = i + 1 
        Next
        Sheets("Mapping").Select
End With
 
Upvote 0

Forum statistics

Threads
1,224,816
Messages
6,181,139
Members
453,021
Latest member
Justyna P

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