If certain text is in a cell . . .
You allude to the fact that the first sheet in the series will be different
depending on the sheet being checked. In you example you use
Open Orders - P 10 sheet being checked
Open Orders - P 1 first sheet in the series
However, in your code, you don't check sheets that don't start with "Order
Status"
so how is the first sheet in the series to be determined
? if the name has 2 numbers on the right, then use the first digit of the
two?
? Would "Order Status" then be replace with "Open Orders"
Assume that is the case
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.
--
Regards,
Tom Ogilvy
"Dallman Ross" wrote:
I have VBA code to run web queries on a set of sheets.
I want to add an If-statement such that
If Right(.Name,2) ...
where the dots would finish the statement "is contained
in Range("A1") of the first sheet in the series."
E.g., sheet is named "Open Orders - P 10"; there may
or may not be a need to run that query. If the text
(not number) "10" is found in A1 of the sheet
"Open Orders - P 1", then let's go ahead and bother to
run the web query.
My code so far, which works but doesn't have the above
qualifier:
Dim sh As Worksheet
For Each sh In ThisWorkbook.worksheets
If Left(sh.Name, 12) = "Order Status" Then
' This is where the new If-statement will go _
that begins "If Right(.name,2) ..."
sh.Activate
Range("A2").Select
Selection.QueryTable.Refresh _
BackgroundQuery:=True
Debug.Print sh.Name & " completed..."
End If
Next
Help?
|