Solved

Excel VBA-  Only Select Worksheets Containing a Comma

Posted on 2013-01-24
7
553 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
Independent Software Vendors: 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

Technology Partners: 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!

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.

756 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