Solved

Excel VBA-  Only Select Worksheets Containing a Comma

Posted on 2013-01-24
7
546 Views
Last Modified: 2013-01-24
Hi Experts :)

Quick question... Is there a way to select only worksheet's whose name contains a comma?

If so what would be the VBA code for it?

I would like all worksheets containing commas selected.  They will all be next to each also, just FYI if that would make a difference.

Thank you for your assistance!
0
Comment
Question by:"Abys" Wallace
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38815572
select them to do what
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38815578
Would the following Macro help you?

Sub activateSheet(sheetname As String)
'activates sheet of specific name
    Worksheets(sheetname).Activate
End Sub

Basically you want to make use of the .Activate function. Or you can use the .Select function like so:

Sub activateSheet(sheetname As String)
'selects sheet of specific name
    Sheets(sheetname).Select
End Sub
0
 
LVL 15

Expert Comment

by:Ess Kay
ID: 38815590
try this
send this function a comma


Sub activateSheet(sheetname As String)
DIM Sheetfound = ""
 For Each sheet In ActiveWorkbook.Sheets
    If sheet.Name Like "*" & sheetname & "*" Then
       Sheetfound = sheet.Name
         EXIT FOR
    End If
 Next
    Worksheets(sheetfound).Activate
End Sub
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 13

Expert Comment

by:Shanan212
ID: 38815734
Sub selector()
    Dim comp1() As String, ws As Worksheet
 
    For Each ws In ActiveWorkbook.Worksheets
        If ws.Name Like "*,*" Then
            Worksheets(ws.Name).Select (False)
        End If
    Next ws
    
End Sub

Open in new window


Try above
0
 

Author Comment

by:"Abys" Wallace
ID: 38815787
Hi esskayb2d...  Thank you for your help!

I attempted to use the latter code but it's not functioning.  I attached a sample workbook to assist.  

I placed your code in a module named:  modSelectWS and attempted to Step through the code but the "DIM Sheetfound = "" is in RED and the remaining code advises I'm unable to rename a sheet the same as one that already exists.

I was selecting the sheet because I want to copy the range A3:F5 from the "Email Daily Stats" sheet onto each sheet that has a name on it with the following format:  "Last Name, First Name" in that sheets A1:F3 range.. cell A3 should contain the worksheet's name

I was thinking selecting each sheet with a comma would be the easiest as the Master workbook contains over 20 sheets outside of the ones with the employee names.

Thank you again ~
SampleDeleteWSBasedCriteria.xlsm
0
 
LVL 13

Accepted Solution

by:
Shanan212 earned 500 total points
ID: 38815856
see attached with my code above
SampleDeleteWSBasedCriteria.xlsm
0
 

Author Closing Comment

by:"Abys" Wallace
ID: 38815962
Shanan212:
You came through again, appreciate!  :)

Kindest Regards
0

Featured Post

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question