Results 1 to 4 of 4

Macro Stopped working: Find not Finding

Threaded View

  1. #1
    Forum Contributor
    Join Date
    10-28-2009
    Location
    Portland, Maine
    MS-Off Ver
    Excel 2003
    Posts
    102

    Macro Stopped working: Find not Finding

    I put together the following code to copy a set of values from a data entry screen into a summary table. The code worked perfectly for me for a long time. However, one day last week it just stopped working!

    The code is no longer finding the date on the data entry screen on the summary table. I added some code to make sure it wasn't related to formatting and it seemed to fix it. But when I opened the file the next day it wasn't working again!!

    So now I'm asking for some help. I've attached a test file and the code.

    Any ideas would be greatly appreciated!!!

    Sub LOG()
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' Definitions;
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim v As Range
    Dim t1
    Dim t2
    Dim List As Range
    Dim FindString
    Dim response
        Set v = Sheet1.Range("LOG_VALUES") 'summary values 'v'
        Set t1 = Sheet1.Range("TODAY") 'today's date as default value in input box
            t1 = Format(Date, "dd-mmm-yy") 'format
            t2 = InputBox("What date do you want to archive?", _
            "D A T E      S E L E C T", t1) 'end user option to change default value
        Set List = Sheet5.Range("DateRange") 'search range
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' manage alerts;   Set to False
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    With Application
    .DisplayAlerts = False
    .ScreenUpdating = False
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' Activate search range
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Sheet5.Activate
        List.Activate
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' find date and set as 'C'
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim c As Range
        Set c = Selection.Find(What:=t2, MatchCase:=False, SearchFormat:=False)
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' check to make sure date value 'C' was found
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        If Not c Is Nothing Then
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' Offset from 'C' to define paste location
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    Dim p As Range
        Set p = c.Offset(0, 1)
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' Check to make sure paste range is empty.
    ''''' --> If empty, copy v, paste to p and return to data entry
    ''''' --> If <>"", confirm override 'y/n', if N = return to data entry, if Y = paste to p
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    If p = "" Then
        v.Copy
        p.PasteSpecial Paste:=xlPasteValues, Transpose:=True
        Sheet1.Activate
        Exit Sub
    
        Else
            response = MsgBox(c & Space(1) & "already has data" & _
                vbCrLf & Space(1) & "Do you want to override?", vbYesNo + vbQuestion, "Confirm Change")
            If response = vbNo Then
            Sheet1.Activate
                Exit Sub
            End If
        End If
        v.Copy
        p.PasteSpecial Paste:=xlPasteValues, Transpose:=True 'if yes, paste values from 'v'
        Sheet1.Activate
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' if c is nothing
    ''''' --> IF no match is found show message box
    ''''' --> return to data entry
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
        Else
        MsgBox EnteredCRN & " Date not found" ' If else, value 'C' not found show message
        Sheet1.Activate 'Home...
        End If
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    ''''' manage alerts;   Set to True
    ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
    .DisplayAlerts = True
    .ScreenUpdating = True
    .CutCopyMode = True
    
    End With
    
    End Sub
    Attached Files Attached Files
    Last edited by yunesm; 07-26-2011 at 10:11 PM.

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