Check dynamic range for specific value

THEEND

New Member
Joined
Mar 17, 2022
Messages
14
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
Hi,
As part of a larger VBA project, I need to check 4 columns to see if any values have been incorrectly entered - values need to be entered by the user as whole numbers without leading zeros, so "3" not "0.03". As such, I need to check to see if there are any cells in the column ranges containing "0.0"s - if there are, I have already devised a fix for that, but if there aren't, I need it to skip the FIX stage and move onto the next stage, which is called: COVER. Below is what I have devised to determine whether there are any "0.0"s in the ranges but I don't know how get it to skip on to the COVER section if there are no "0.0"s.
Hope some one can please advise.
Many thanks.

VBA Code:
    'Determine if any 'Contribution Rate' columns contain "0.0" - if they do, go to FIX
    Last = Cells(Rows.Count, "A").End(xlUp).Row
    For I = Last To 1 Step -1
        If (Cells(I, "Y").Value) Like "0.0*" Then GoTo FIX
    Next I
        For I = Last To 1 Step -1
        If (Cells(I, "Z").Value) Like "0.0*" Then GoTo FIX
    Next I
    For I = Last To 1 Step -1
        If (Cells(I, "AA").Value) Like "0.0*" Then GoTo FIX
    Next I
    For I = Last To 1 Step -1
        If (Cells(I, "AB").Value) Like "0.0*" Then GoTo FIX
    Next I

   
FIX:
    'Fix code goes here

COVER:
 

Excel Facts

Last used cell?
Press Ctrl+End to move to what Excel thinks is the last used cell.
Maybe something like this:
VBA Code:
Sub CheckValue()
    'Determine if any 'Contribution Rate' columns contain "0.0" - if they do, go to FIXX
    Application.ScreenUpdating = False
    Dim last As Long, rng As Range
    last = Cells(Rows.Count, "A").End(xlUp).Row
    For Each rng In Range("Y1:AB" & last)
        If rng.Value Like "0.0*" Then
            'Fixx code goes here
        Else
            'COVER code goes here
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Maybe something like this:
VBA Code:
Sub CheckValue()
    'Determine if any 'Contribution Rate' columns contain "0.0" - if they do, go to FIXX
    Application.ScreenUpdating = False
    Dim last As Long, rng As Range
    last = Cells(Rows.Count, "A").End(xlUp).Row
    For Each rng In Range("Y1:AB" & last)
        If rng.Value Like "0.0*" Then
            'Fixx code goes here
        Else
            'COVER code goes here
        End If
    Next rng
    Application.ScreenUpdating = True
End Sub
That worked perfectly, thank you so much!
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,241
Members
452,622
Latest member
Laura_PinksBTHFT

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