Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default Runtime error 9 in "How to find a date in a range with VBA ?"

Dim lngRow As Long
Dim dteInput As Date
'Range has several dates formatted as "ddd, dd/mm/aa"
Range("G3:G10").Select

'dteInput is being copied from a cell that has "23/11/2004" as a date value
(format cell = date)
'I use Windows XP, Excel XP with Spanish settings!

With Selection
'I get a runtime error 9 here

lngRow = Cells.Find(What:=dteInput, After:=ActiveCell, LookIn:=xlFormula,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Row

MsgBox "lngRowDteImport = " & lngRowDteImport, vbInformation

End With

If lngRowDteImport 0 Then 'Import Fecha already exists in Range G3:G10!

MsgBox "Date " & CStr(dteImport) & exists", vbInformation, "Terminated"
Exit Sub

Any idea why this gives an error?

TIA
Martin
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 983
Default Runtime error 9 in "How to find a date in a range with VBA ?"

One possible reason is if the sheet is protected or hidden then you will have
a problem.

"Martin Los" wrote:

Dim lngRow As Long
Dim dteInput As Date
'Range has several dates formatted as "ddd, dd/mm/aa"
Range("G3:G10").Select

'dteInput is being copied from a cell that has "23/11/2004" as a date value
(format cell = date)
'I use Windows XP, Excel XP with Spanish settings!

With Selection
'I get a runtime error 9 here

lngRow = Cells.Find(What:=dteInput, After:=ActiveCell, LookIn:=xlFormula,
LookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext,
MatchCase:=False, SearchFormat:=False).Row

MsgBox "lngRowDteImport = " & lngRowDteImport, vbInformation

End With

If lngRowDteImport 0 Then 'Import Fecha already exists in Range G3:G10!

MsgBox "Date " & CStr(dteImport) & exists", vbInformation, "Terminated"
Exit Sub

Any idea why this gives an error?

TIA
Martin

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
"Microsoft Visual Basic runtime error '424' object required". SharonG. Excel Worksheet Functions 0 July 5th 06 01:36 AM
How do I correct Runtime error "53" in excel 2003 mendip04 Excel Discussion (Misc queries) 1 December 12th 05 10:22 PM
Excel:Runtime Error 7 "Not enough Memory" with CreateObject (SAP.B sebastienm Excel Programming 0 July 24th 04 08:35 AM
Runtime Error "1004" Select Method of Range Class Failed Stephen[_7_] Excel Programming 4 April 10th 04 06:28 AM


All times are GMT +1. The time now is 08:46 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"