+ Reply to Thread
Results 1 to 2 of 2

Formula & Macro

  1. #1
    Registered User
    Join Date
    05-17-2006
    Location
    Battle Creek, MI USA
    Posts
    11

    Formula & Macro

    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" if the value of cells in column L and R is 1

  2. #2
    Kevin B
    Guest

    RE: Formula & Macro

    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

    --
    Kevin Backmann


    "nik_gujarathi" wrote:

    >
    > 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" if
    > the value of cells in column L and R is 1
    >
    >
    > --
    > nik_gujarathi
    > ------------------------------------------------------------------------
    > nik_gujarathi's Profile: http://www.excelforum.com/member.php...o&userid=34522
    > View this thread: http://www.excelforum.com/showthread...hreadid=546036
    >
    >


+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1