Application.FindFormat.NumberFormat Help! (1 Viewer)

stephen81

Registered User.
Local time
Today, 18:45
Joined
Nov 27, 2002
Messages
198
I'm trying to replace all the dates in my workbook in a specific date format with a different format using the following code...

Code:
With Application
    .FindFormat.NumberFormat = "dd-mmm-yyyy"
    .ReplaceFormat.NumberFormat = "mm/dd/yyyy"
End With

Cells.Replace What:="-", Replacement:="-", LookAt:=xlPart, SearchOrder:=xlByRows, _
    MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True

Each time I run it though, even if these are the only lines existing in my macro, I get a generic Run-time error '1004': Application-defined or object-defined error

In debug mode if I hover over the
FindFormat.NumberFormat = "dd-mmm-yyyy"
and
ReplaceFormat.NumberFormat = "dd-mmm-yyyy"
lines, it pops up with

.FindFormat.NumberFormat = null
and
.ReplaceFormat.NumberFormat = null.


Anyone got any ideas?
 

chergh

blah
Local time
Today, 18:45
Joined
Jun 15, 2004
Messages
1,414
You want to refer to the worksheet object and not the application object.

Instead of
Code:
with application

use

Code:
with application.workbooks("WorkbookName.xls").worksheets("WorksheetName")
 

Users who are viewing this thread

Top Bottom