Formula & Macro

N

nik_gujarathi

Hello friends
I have a formula in each cell of column L and R.
Example
Formula in cell L6 is =IF(J6<>K6,0,1) & Formula in cell R6 is
IF(P6<>Q6,0,1)
I was looking for a macro that will give a error message "Warning" i
the value of cells in column L and R is
 
K

Kevin B

I select the cells in each of the columns (L and R) and name them CheckValues.

The following macro assumes that the sheet in use is Sheet1, change this to
whatever is appropriate to your environment.

Open the VBE (Alt + F11) and in a new module enter the following code:

Sub CheckCells()

Dim rng As Range
Dim wb As Workbook
Dim ws As Worksheet
Dim i As Integer

Set wb = ActiveWorkbook
Set ws = wb.Worksheets("Sheet1")
Set rng = Range("CheckValues")

For i = 1 To rng.Cells.Count
If rng.Cells(i) = 1 Then
MsgBox "A cell in either R or L has evaluated to a 1."
Exit For
End If
Next i

Set rng = Nothing
Set wb = Nothing
Set ws = Nothing

End Sub

Open the worksheet module for whatever sheet the ranges are on and enter the
following in the Worksheet's Change event:

Private Sub Worksheet_Change(ByVal Target As Range)

CheckCells

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top