excelhelp123456789

New Member
Joined
Oct 28, 2015
Messages
1
Hi,

I'm working on the code below and can't seem to figure out why I'm continually getting the application defined / object defined error. I had it working before and for some reason it's now giving me this error every time. The issue seems to surround the With Statement when the ".Pattern" begins.

The goal of this code is to validate data in a cell with a formula that outputs a number based on the input of two other cells. One cell value must be larger than the first and, if not, pop up with an error and color the cell. I need it to run behind the scenes on every row as the user goes through the spreadsheet.

Any tips/suggestions would be greatly appreciated. Thanks in advance!

Code:
Dim rng1 As Integer
Dim rng2 As Integer




rng1 = Cells(ActiveCell.Row - 1, 4)
rng2 = Cells(ActiveCell.Row - 1, 7)
        
        If rng2 > 0 Then
            If rng1 > rng2 Then
                Cells(ActiveCell.Row - 1, 7).Interior.Color = RGB(255, 0, 0)
                MsgBox "Incorrect Entry: Please contact supervisor"
            Else
                Range("G" & ActiveCell.Row).Select
                With Selection.Interior
                    .Pattern = xlSolid
                    .PatternColorIndex = xlAutomatic
                    .ThemeColor = xlThemeColorAccent1
                    .TintAndShade = 0.799981688894314
                End With
            End If
        End If
End Sub
 

Excel Facts

Quick Sum
Select a range of cells. The total appears in bottom right of Excel screen. Right-click total to add Max, Min, Count, Average.

Forum statistics

Threads
1,214,869
Messages
6,122,015
Members
449,060
Latest member
LinusJE

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