Solved

Excel VBA-  Only Select Worksheets Containing a Comma

Posted on 2013-01-24
7
561 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

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…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

717 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