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
Bookmarks