VBA Data Validation populate error in For Next loop

Rowland Hamilton

Active Member
Joined
Nov 13, 2009
Messages
250
Can anyone explain why this code breaks on row 21,833 after working since row 8? Note: vntMatch is defined as variant and does not change. UsedRange is getting the proper row count (27,852)
Dim vntMatch As Variant

Code:
 vntMatch = Application.Match("Manual", shtCashForecast.Range("7:7"), 0)
   If Not IsError(vntMatch) Then
        'Loop through Manual column, offsets to start with cell under header.
        For Each rCell In shtCashForecast.Range("7:7").Cells(1, vntMatch).Offset(1, 0).Resize(shtCashForecast.UsedRange.Rows.Count, 1).Cells
            
            'Adds validation to Manual column cells if total forecast for row > 0
            'Changing offset from -1 to -3 since added 2 columns
            If InStr(rCell.Offset(0, -3).Formula, "=") > 0 Then
                With rCell.Validation
                    .Delete
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=ManualMonths"
                    .IgnoreBlank = True
                    .InCellDropdown = True
                    .InputTitle = ""
                    .ErrorTitle = ""
                    .InputMessage = ""
                    .ErrorMessage = ""
                    .ShowInput = True
                    .ShowError = True
                End With
            End If
        Next
   End If
 

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.
Correction: Doesn't break on Instr, but rather on

Code:
                    .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:="=ManualMonths"
 
Upvote 0

Forum statistics

Threads
1,223,968
Messages
6,175,677
Members
452,666
Latest member
AllexDee

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