ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   "Not" and "Not Like" (https://www.excelbanter.com/excel-programming/299264-not-not-like.html)

Francesco Sblendorio

"Not" and "Not Like"
 
If WSh.Name < "Admin" and < "Server * Projection Seed Values"

First of all, this line lacks 'WSh.Name' before '< "Server *... '
Obviously this test will not perform a LIKE compare.
To solve your problem, you can do so:

If WSh.Name < "Admin" and Left(WShName, 7) < "Server " and Right(WShName,
23) < " Projection Seed Values" Then

Be attention: "Server " ends with a space, " Projection Seed Values" begins
with a space.




Grant Reid

"Not" and "Not Like"
 
Hi

I need to perform arbitary actions on all sheets in my workbook except for a
sheet with the name "Admin" and any sheets with the following naming
convention "Server * Projection Seed Values". Am at my wits end with this
one. Can anyone help. See my code below;

Dim qt As QueryTable
Dim WSh As Worksheet

For Each WSh In ThisWorkbook.Worksheets
If WSh.Name < "Admin" and < "Server * Projection Seed Values"
Then '<------ This is the problem area
'Perform action here
End If
Next WSh

End Sub

Many Thanks - Grant



Francesco Sblendorio

"Not" and "Not Like"
 

If WSh.Name < "Admin" and Left(WShName, 7) < "Server " and

Right(WShName,
23) < " Projection Seed Values" Then



ahem... I wrote "WShName" instead of "WSh.Name"



Andy Pope

"Not" and "Not Like"
 
Hi Grant,

You need to add WSh.name to the second part of the test as well.

If WSh.Name < "Admin" and WSh.Name < "Server * Projection Seed
Values" Then

Cheers
Andy

Grant Reid wrote:

Hi

I need to perform arbitary actions on all sheets in my workbook except for a
sheet with the name "Admin" and any sheets with the following naming
convention "Server * Projection Seed Values". Am at my wits end with this
one. Can anyone help. See my code below;

Dim qt As QueryTable
Dim WSh As Worksheet

For Each WSh In ThisWorkbook.Worksheets
If WSh.Name < "Admin" and < "Server * Projection Seed Values"
Then '<------ This is the problem area
'Perform action here
End If
Next WSh

End Sub

Many Thanks - Grant



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info

Francesco Sblendorio

"Not" and "Not Like"
 
If WSh.Name < "Admin" and (Left(WShName, 7) < "Server " OR Right(WShName,
23) < " Projection Seed Values") Then

7 and 23 are lengths of "Server " and " Projection Seed Values"



Grant Reid

"Not" and "Not Like"
 
Hi

Many thanks to those who reponded , but...... I'm still not getting the
expected result. I'm trying to refresh all query tables in the workbook,
except for a worksheet named "Admin" and all worksheets with a naming
convention of "Server 1 Database Space Summary", "Server 2 Database Space
Summary", "Server 3 Database Space Summary" etc etc. I've tried variations
of the responses posted thus far but without success. Perhaps I'm missing
the obvious or hitting a late afternoon blank. I've re-posted my code below
hoping that someone will highlight the problem for me. Many thanks in
advance

Sub RefreshExisting()

Dim qt As QueryTable
Dim WSh As Worksheet
Dim strQueryName As String

For Each WSh In ThisWorkbook.Worksheets
For Each qt In WSh.QueryTables
strQueryName = WSh.Range("AM2")
If WSh.Name < "Admin" And WSh.Name < "Server * Projection Seed
Values" Then
If InStr(qt.Name, strQueryName) Then
qt.Refresh BackgroundQuery:=False
End If
End If
Next qt
Next WSh
End Sub

Kind Regards - Grant



Bob Phillips[_6_]

"Not" and "Not Like"
 

If WSh.Name < "Admin" and _
Not WSh.Name like "Server * Projection Seed Values" Then

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Grant Reid" wrote in message
...
Hi

I need to perform arbitary actions on all sheets in my workbook except for

a
sheet with the name "Admin" and any sheets with the following naming
convention "Server * Projection Seed Values". Am at my wits end with this
one. Can anyone help. See my code below;

Dim qt As QueryTable
Dim WSh As Worksheet

For Each WSh In ThisWorkbook.Worksheets
If WSh.Name < "Admin" and < "Server * Projection Seed Values"
Then '<------ This is the problem area
'Perform action here
End If
Next WSh

End Sub

Many Thanks - Grant





Francesco Sblendorio

"Not" and "Not Like"
 
Does it works? Which solution have you used?




Grant Reid

"Not" and "Not Like"
 
Hi

Many thanks to all who responded.

Kind Regards - Grant



Grant Reid

"Not" and "Not Like"
 
Hi Francesco

I tried all the suggestions and the only ones that did the trick for me were
the solutions posted by you and Bob. Very elegant, both of them.

I do not know why the solution posted by Andy did'nt do it for me. Perhaps
it was late afternoon brain-fog ;-)

Once again, many thanks to you all

Kind Regards - Grant



Bob Phillips[_6_]

"Not" and "Not Like"
 
and I had thought my little gem had got lost in all the fog<vbg

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Grant Reid" wrote in message
...
Hi Francesco

I tried all the suggestions and the only ones that did the trick for me

were
the solutions posted by you and Bob. Very elegant, both of them.

I do not know why the solution posted by Andy did'nt do it for me. Perhaps
it was late afternoon brain-fog ;-)

Once again, many thanks to you all

Kind Regards - Grant





Andy Pope

"Not" and "Not Like"
 
I left out the LIKE operator.

Grant Reid wrote:

Hi Francesco

I tried all the suggestions and the only ones that did the trick for me were
the solutions posted by you and Bob. Very elegant, both of them.

I do not know why the solution posted by Andy did'nt do it for me. Perhaps
it was late afternoon brain-fog ;-)

Once again, many thanks to you all

Kind Regards - Grant



--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com