LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default 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?


 
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
Copy text from cell to cell with one cell changing text Bobby Excel Worksheet Functions 5 March 15th 07 11:09 PM
Setting the text in a cell to the text of a cell on a different sheet in the same workbook Max C Excel Programming 6 December 28th 06 04:35 PM
select text in cell based on text from another cell, paste the text at the begining of a thrid cell, etc... jsd219 Excel Programming 0 October 19th 06 05:04 PM
Deleting Rows based on text in cell & formatting cell based on text in column beside it Steve Excel Programming 4 February 26th 04 03:31 PM
extracting text from within a cell - 'text to rows@ equivalent of 'text to columns' Dan E[_2_] Excel Programming 4 July 30th 03 06:43 PM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"