Problem finding cell contents

I

IanC

I have the following code which is causing me a headache. The idea is to
find the current version of an Excel template file. The problem lies in the
section between the rows of hyphens. Things go wrong on the line followed by
asterisks, though I think the problem lies with the previous line.

The partucular file I'm working with does not contain SD so I need t to step
onto the next section looking for sUpdRoot & " v". The problem is that
"cell" obviously contains something and th code jumps to "cont:".

How can I modify the code so that if SD isn't found it will look for
sUpdRoot & " v"?

Many thanks.

--
Ian
--

Private Sub CheckVersion(sTPPath, sUpdRoot, dVer, sVerRep, sCurPath,
sUpdFile)
Dim lLoc As Long
Dim dNewVer As Double
Dim cell As Range
Dim sSearch As String

' Checks version of existing template
With Application
.EnableEvents = False
Workbooks.Open Filename:= _
sTPPath & "\" & sUpdRoot & ".xlt", _
UpdateLinks:=0, Editable:=True
On Error Resume Next
With ActiveWindow
.WindowState = xlNormal
.Top = 100
.Left = 300
.Height = 50
.Width = 50
End With
'----------------------
'Find cell containing "SD" (if any)
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 GoTo cont '************
On Error Resume Next
'Find cell containing "filename v" (if any)
Set cell = .Cells.Find(What:=sUpdRoot & " v", _
After:=.ActiveCell, _
LookIn:=xlValues, _
LookAt:=xlPart, _
SearchOrder:=xlByColumns, _
SearchDirection:=xlNext, _
MatchCase:=False)
On Error GoTo 0
If Not cell Is Nothing Then

'----------------------
cont:
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 older than existing
template"
ElseIf dNewVer = dVer Then
sVerRep = "Failure - Current version is up to date (v" &
dVer & ")"
ElseIf dVer < 6 Then
sVerRep = "Failure - Current version is too old (v" & dVer &
")"
Else
sVerRep = "Current version is " & dVer
End If
Else
sVerRep = "Failure - Unable to determine version of existing file"
End If

.Visible = True
.EnableEvents = True
End With

End Sub
 
I

IanC

IanC said:
I have the following code which is causing me a headache. The idea is to
find the current version of an Excel template file. The problem lies in the
section between the rows of hyphens. Things go wrong on the line followed
by asterisks, though I think the problem lies with the previous line.

The partucular file I'm working with does not contain SD so I need t to
step onto the next section looking for sUpdRoot & " v". The problem is
that "cell" obviously contains something and th code jumps to "cont:".

How can I modify the code so that if SD isn't found it will look for
sUpdRoot & " v"?
'Find cell containing "SD" (if any)
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 GoTo cont '************
I'm an idiot (please feel free to disagree). The answer was staring me in
the face. the string SD was being found in the worksheet, but not as I
expected it. It was in the word Tuesday. All I needed to do was change
MatchCase to True.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top