Solved

Excel VBA-  Only Select Worksheets Containing a Comma

Posted on 2013-01-24
7
536 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
Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will demonstrate in Microsoft Excel how to add style and sexy appeal to horizontal bar charts.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now