Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #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
---


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Error trapping?

Untested ...

Private Sub CheckVersion(sTPPath, sUpdRoot, dVer, sVerRep, sCurPath,
sUpdFile)
Dim lLoc As Long
Dim dNewVer As Double
Dim cell As Range
Dim cell2 As Range
' Checks version of existing template
With Application

.EnableEvents = False

Workbooks.Open Filename:= _
sTPPath & "\" & sUpdRoot & ".xlt", _
UpdateLinks:=0, Editable:=True

On Error Resume Next
Set cell = .Cells.Find(What:="SD", _
After:=.ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If Not cell Is Nothing Then
On Error Resume Next
Set cell2 = .Cells.Find(What:=sUpdRoot & " v", _
After:=.ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If Not cell2 Is Nothing Then Set cell = cell2

lLoc = InStrRev(cell.Value, "v")
dVer = Val(Right(cell.Value, Len(cell.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
End If

.Visible = True
.EnableEvents = True
End With
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my addy)



"IanC" wrote in message
...
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
---




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Error trapping?

Thanks, Bob. It needed a bit of modification, but it works fine now :-)

--
Ian
--
"Bob Phillips" wrote in message
...
Untested ...

Private Sub CheckVersion(sTPPath, sUpdRoot, dVer, sVerRep, sCurPath,
sUpdFile)
Dim lLoc As Long
Dim dNewVer As Double
Dim cell As Range
Dim cell2 As Range
' Checks version of existing template
With Application

.EnableEvents = False

Workbooks.Open Filename:= _
sTPPath & "\" & sUpdRoot & ".xlt", _
UpdateLinks:=0, Editable:=True

On Error Resume Next
Set cell = .Cells.Find(What:="SD", _
After:=.ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If Not cell Is Nothing Then
On Error Resume Next
Set cell2 = .Cells.Find(What:=sUpdRoot & " v", _
After:=.ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If Not cell2 Is Nothing Then Set cell = cell2

lLoc = InStrRev(cell.Value, "v")
dVer = Val(Right(cell.Value, Len(cell.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
End If

.Visible = True
.EnableEvents = True
End With
End Sub

--
---
HTH

Bob


(there's no email, no snail mail, but somewhere should be gmail in my
addy)



"IanC" wrote in message
...
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
---






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
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 07:00 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"