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

What is the fastest way to copy a formula?
If A2:A50000 contain data. Enter a formula in B2. Select B2. Double-click the Fill Handle and Excel will shoot the formula down to B50000.
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,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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