View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Dallman Ross Dallman Ross is offline
external usenet poster
 
Posts: 390
Default If certain text is in a cell . . .

Tom Ogilvy helped me out last week and gave me some good ideas.
I've worked on my macro some more and now have the below code.
Any comments are welcome -- I'm learning. E.g., I don't know
how to use On-Error statements, so I didn't include anly.

This seems to work fine now. Basicaly, run web queries on
pages if certain conditions are met. First, the right part
of the sheet name should appear in A1 of the first sheet on
which queries get run. Second, run one of the othe sheets
regardless. Third, run the "Pending" sheet only if outside
market hours.

Here's my code.

-------------

Sub OrderWebQueries()
'
' Macro last edited 8/16/2007 by Dallman Ross
' Shortcut Ctrl + U

' updates Open Order data via web queries

Dim sh As Worksheet
Dim pNumStr As String

pNumStr = ThisWorkbook.Worksheets("Order Status - P 1").Range("A1")

For Each sh In ThisWorkbook.Worksheets

sh.Activate
If Left(sh.Name, 12) = "Order Status" Then

' if the right two chars of the current Sheet's _
name appear (space-delimited) on or after char 5 _
of the 1st sheet's A1 ...

If InStr(5, pNumStr, Right(sh.Name, 2)) 0 _
Or sh.Name = "Order Status - New" Then

Call doQuery

ElseIf sh.Name = "* Pending" Then

Dim hhTime As Long
hhTime = Format(Time, "hh")

' N.B.: my local time is Central European

If hhTime < 15 Or hhTime 22 Or _
Weekday(Now, vbMonday) 5 Then

Call doQuery

End If
End If
End If
Next
Sheet0.Select ' MergeSheet
End Sub


Private Sub doQuery()
Dim sh As Worksheet

Set sh = ActiveSheet
Debug.Print sh.Name

sh.Range("A2").Select
Selection.QueryTable.Refresh BackgroundQuery:=True
End Sub

--
dman

==========================
In , Tom Ogilvy
spake thusly:


Dim sh As Worksheet

For Each sh In ThisWorkbook.worksheets
If Left(sh.Name, 12) = "Order Status" Then
sName = Replace(sh.Name,"Order Status","Open Orders")
sName = Left(sName,len(sName)-1)
on Error Resume Next
set sh = worksheets(sName)
on Error goto 0
bskip = False
if not sh is nothing then
if application.Countif(sh.Range("A:A","*" & _
Right(sh.Name,2) & "*") 0 then
bskip = True
end if
end if
' This is where the new If-statement will go _
that begins "If Right(.name,2) ..."
if not bskip then
sh.Activate
Range("A2").Select
Selection.QueryTable.Refresh _
BackgroundQuery:=True

Debug.Print sh.Name & " completed..."
end if
End If
Next

Take the right "*" off in the countif if column 1 will contain the two digit
number only on the right end of the string.