LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Error trapping?

I need to look for a specific text string within a spreadsheet then, if it
isn't found, look for another text string.

The problem I have with the existing code is that if the 1st search string
(SD) isn't found, it doesn't look for the second string. If is DOES find the
first string, it goes on to look for the second string anyway (currently
commented out). This wouldn't be a problem if the second string exists, but
if it doesn't then the following doesn't execute.

I know I'm going about this the wrong way, but I'm not sure how to remedy
the situation. Any ideas?

My code is below:

Private Sub CheckVersion(sTPPath, sUpdRoot, dVer, sVerRep, sCurPath,
sUpdFile)
Dim lLoc As Long
Dim dNewVer As Double
' Checks version of existing template
With Application
.EnableEvents = False
Workbooks.Open Filename:= _
sTPPath & "\" & sUpdRoot & ".xlt", _
UpdateLinks:=0, Editable:=True
On Error GoTo noSD
.Cells.Find(What:="SD", After:=.ActiveCell, LookIn:=xlValues,
LookAt:= _
xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
False).Activate
' ***** Second string find to go here *****
' On Error GoTo noSD
' .Cells.Find(What:=sUpdRoot & " v", After:=.ActiveCell,
LookIn:=xlValues, LookAt:= _
' xlPart, SearchOrder:=xlByColumns, SearchDirection:=xlNext,
MatchCase:= _
' False).Activate
lLoc = InStrRev(.ActiveCell.Value, "v")
dVer = Val(Right(.ActiveCell.Value, Len(.ActiveCell.Value) - lLoc))
sUpdFile = Dir(sCurPath & "\" & sUpdRoot & "*.xlt")
sUpdFile = Left(sUpdFile, Len(sUpdFile) - 4)
lLoc = InStrRev(sUpdFile, "v")
dNewVer = Val(Right(sUpdFile, Len(sUpdFile) - lLoc))
If dNewVer <= dVer Then
sVerRep = "Failure - Update version is the same or older than
existing template"
Else
sVerRep = "Current version is " & dVer
End If
.Visible = True
.EnableEvents = True
End With
GoTo subend
noSD:
sVerRep = "Failure - Unable to update from this version"
subend:
End Sub


Many thanks.

---
Ian
---


 
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
Trapping #VALUE! error RhysPieces Excel Discussion (Misc queries) 6 August 22nd 07 03:13 AM
while deleting rows it finds an error - error trapping Janis Excel Programming 2 July 19th 07 12:12 AM
Error trapping hshayh0rn Excel Programming 1 May 4th 06 05:42 PM
Error Trapping Neil Excel Programming 1 January 5th 04 04:38 PM
error trapping libby Excel Programming 5 November 25th 03 10:57 PM


All times are GMT +1. The time now is 06:53 AM.

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

About Us

"It's about Microsoft Excel"