Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
finding the cell with min value and returning the contents of neig | Excel Worksheet Functions | |||
Finding MAX Value of Part of Cell Contents | Excel Programming | |||
Finding row # of last cell containing contents | Excel Worksheet Functions | |||
Finding cell contents based on certain criteria | Excel Discussion (Misc queries) | |||
Finding Cell Contents | Excel Programming |