+ Reply to Thread
Results 1 to 3 of 3

when using InStr function, it fills the target cell repeating info

Hybrid View

  1. #1
    Registered User
    Join Date
    01-08-2008
    Posts
    2

    when using InStr function, it fills the target cell repeating info

    I have the following code. I want it just to use InStr to find if a certain expression is contained within the cell, and if so perform a simple highlight action then add the date to the end of the cell's text.

    used in the Sheet 'Change' event:
        If Target.Cells.Column = 1 And InStr(Target.Cells.Value,"to be opened") > 0  Then
            ActiveCell.Offset(0, 1).Interior.ColorIndex = 45
            ActiveCell.Value = ActiveCell.Value & " " & Now
            Target.Cells.Interior.ColorIndex = 0
        End If
    but i just get the cell filled up with the current date/time until it can't fit anymore repeats

    i've tried using target.cells.value instead of activecell, and declaring a variable with the instr value, or using a variable with the cell value inside the InStr syntax, but it always happens

    i'm a bit confused

    anyone know what's going on?

    appreciate any help

  2. #2
    Registered User
    Join Date
    01-08-2008
    Posts
    2
    ah, genius
    works great
    thanks

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    You're retriggering the change event when you change the cell in the event code. Not sure what logic you want, but maybe this:
    Private Sub Worksheet_Change(ByVal Target As Range)
        Application.EnableEvents = False
        With Target
            If .Column = 1 And InStr(.Value, "to be opened") > 0 Then
                .Offset(, 1).Interior.ColorIndex = 45
                .Value = .Value & Format(Now, " yyyy-mmdd hh:mm")
                .Interior.ColorIndex = xlColorIndexNone
            End If
        End With
        Application.EnableEvents = True
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. returning something in a cell if another cell has info input
    By stevesunfold in forum Excel General
    Replies: 14
    Last Post: 04-01-2008, 08:51 AM
  2. Replies: 4
    Last Post: 12-14-2007, 05:39 PM
  3. Function to return Cell Addresses
    By stvgarner in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-05-2007, 11:46 AM
  4. Insertrow macro
    By asimsid in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-27-2007, 12:20 PM
  5. Pulling a worksheet name from cell value (custom function needing help)
    By Kurisu in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-21-2006, 09:09 PM

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