VB:For Each ws In sheets If instr(ws.name, "Q") > 0 Then Else End If
Greetings ...
How can I select sheets in a workbook based on the premise that the sheetname does not have the letter "Q" in it? Please advise.
New to forum, so apologies if format is not kosher.
I have a group of 50+ workbooks which are all set up in the following format:
-Contains 30+ sheets.
-Sheet names are varied, but follow a pattern. I try to keep the sheet names consistant on all workbooks so that it is easier to reference, but other users make this impossible.
-However, I managed to keep two things consistant: There are two categories of sheets. In one group all sheetnames have a "Q" in them and in the other group all sheetnames DON'T have a "Q" in them.
Here is my problem:
I need to run a macro to perform retative tasks on the GROUP OF SHEETS WITHOUT A "Q". To begin the macro I need to select these sheets and copy them to a new workbook, but since the actual sheetnames are varied, I am having trouble coming up with a flexible way of selecting sheets.
The closest I have come is using a IF ... LIKE ... THEN statement, but I can only get it to work to select the sheets with a "Q" in the name and not the opposite.
Many thanks for all help offered.
lulasi
VB:For Each ws In sheets If instr(ws.name, "Q") > 0 Then Else End If
Eternity is a terrible thought. I mean, where's it going to end??
Greetings ...
Thank you for the reply.
I tried the code, but could only get it to select the second sheet with a "Q" in it. I don't think I was filling in the blanks after the THEN statement correctly.
But I managed to get it to work by combining it with code from another thread. Here it is:
I don't really understand how the blnReplace is making it so multiple sheets are selected together instead of one, but I will take it.VB:Sub Test() Dim blnReplace As Boolean Dim sht As Object blnReplace = True For Each ws In sheets If InStr(ws.Name, "Q") = 0 Then ws.Select blnReplace blnReplace = False End If Next End Sub
Many, many thanks for the help.
lulasi
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks