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!
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