Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Problem finding cell contents

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 157
Default Problem finding cell contents


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

--
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
finding the cell with min value and returning the contents of neig Will Excel Worksheet Functions 1 May 17th 07 10:18 PM
Finding MAX Value of Part of Cell Contents Corey Excel Programming 2 January 12th 07 03:42 AM
Finding row # of last cell containing contents Bob Excel Worksheet Functions 7 January 8th 07 07:13 PM
Finding cell contents based on certain criteria thekovinc Excel Discussion (Misc queries) 1 March 15th 06 07:37 PM
Finding Cell Contents Jeff at Robert Bosch Corp.[_2_] Excel Programming 2 June 10th 05 07:16 PM


All times are GMT +1. The time now is 08:55 PM.

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"