Consulting

Results 1 to 4 of 4

Thread: VBA Code to search for value in worksheet and enter date into next column

  1. #1
    VBAX Regular
    Joined
    Jun 2010
    Posts
    90
    Location

    VBA Code to search for value in worksheet and enter date into next column

    Hi All,

    I wonder if anyone can help me. I need some code to seach a value stored within Worksheet 1 in Worksheet 2. Once the value (which will be a mixture of numbers and special characters) is found in worksheet 2, it will enter in the current date and time into the next column.

    Worksheet 2 has lots of data so I am guessing it would be a loop of some kind.

    Can anyone help me?

    Thanks


    Phil

  2. #2
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Select a cell on the first worksheet and run:

    Sub DateMarker()
        Dim v As Variant
        v = ActiveCell.Value
        Sheets("Sheet2").Activate
        Range("A1").Select
        Set r = Cells.Find(What:=v, After:=ActiveCell)
        If r Is Nothing Then
            MsgBox "Value not found"
            Exit Sub
        Else
            r.Offset(0, 1).Value = Now
        End If
    End Sub
    Change the name of the second sheet to suit your needs.
    Have a Great Day!

  3. #3
    VBAX Regular
    Joined
    Jun 2010
    Posts
    90
    Location
    Quote Originally Posted by GarysStudent View Post
    Select a cell on the first worksheet and run:

    Sub DateMarker()
        Dim v As Variant
        v = ActiveCell.Value
        Sheets("Sheet2").Activate
        Range("A1").Select
        Set r = Cells.Find(What:=v, After:=ActiveCell)
        If r Is Nothing Then
            MsgBox "Value not found"
            Exit Sub
        Else
            r.Offset(0, 1).Value = Now
        End If
    End Sub
    Change the name of the second sheet to suit your needs.
    Thanks for getting back to me so quickly, it works a treat.

    Phil

  4. #4
    VBAX Contributor GarysStudent's Avatar
    Joined
    Aug 2012
    Location
    Lakehurst, NJ, USA
    Posts
    127
    Location
    Thanks for the feedback!
    Have a Great Day!

Posting Permissions

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