Range.Find Date

30percent

Board Regular
Joined
May 5, 2011
Messages
123
Office Version
  1. 2016
Platform
  1. Windows
Hi,

I have the following code that have been working for months. Suddenly today is 04/01/2019 the code stopped working. It couldn't find the cell that contain the date.

Code:
Set Rng = wb.Sheets("Sheet1").Range("A:A")

Set c = Rng.Find(Format(Date, "dddd, mmmm dd, yyyy"), LookIn:=xlValues)
        If Not c Is Nothing Then
            Set rng_Paste = wb.Sheets("Sheet1").Cells(c.Row, c.Column).Offset(0, 11)
            rng_Copy.Copy
            rng_Paste.PasteSpecial Paste:=xlPasteValues
            Application.CutCopyMode = False
        End If

I tried the following code to see if I could work around it.

Code:
Set Rng = ThisWorkbook.Sheets("Sheet1").Range("A:A")

Application.FindFormat.NumberFormat = "[$-x-sysdate]dddd, mmmm dd, yyyy"


Set c = Rng.Find(Date, LookIn:=xlValues, SearchFormat:=True)


If Not c Is Nothing Then
 Debug.Print c.Row
Else
 Debug.Print "Not Found"
End If

Output of the second group of code is "Not Found". Wonder if someone could help point out what's going on here. Why it is that my first group of code working all this time suddenly stopped working? and how I could rewrite it to work. I could confirm that the format of cell of the date that I'm trying to find is "[$-x-sysdate]dddd, mmmm dd, yyyy"
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Does this work?
Code:
Set Rng = wb.Sheets("Sheet1").Range("A:A")

Res = Application.Match(Date, Rng, 0)

If Not IsError(Res) Then 
    Set rng_Paste = wb.Sheets("Sheet1").Cells(Res, c.Column).Offset(0, 11)
    rng_Copy.Copy
    rng_Paste.PasteSpecial Paste:=xlPasteValues
    Application.CutCopyMode = False
End If
 
Upvote 0
I tried both the following code:

Code:
[COLOR=#333333]Res = Application.Match(thisDate, Rng, 0)[/COLOR]

and

Code:
Res = Application.Match(Format(thisDate, "dddd, mmmm dd, yyyy"), Rng, 0)

Both got error 2042.
 
Last edited:
Upvote 0
Try this.
Code:
Dim Res As Variant

    Set Rng = wb.Sheets("Sheet1").Range("A:A")

    Res = Application.Match(CLng(Date), Rng, 0)

    If Not IsError(Res) Then 
        Set rng_Paste = wb.Sheets("Sheet1").Cells(Res, c.Column).Offset(0, 11)
        rng_Copy.Copy
        rng_Paste.PasteSpecial Paste:=xlPasteValues
        Application.CutCopyMode = False
    End If
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,178
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top