Find open workbook set worksheet range

288enzo

Well-known Member
Joined
Feb 8, 2009
Messages
727
Office Version
  1. 2016
Platform
  1. Windows
Hi all,

I need some help, the more I try the worse my code gets :-)

What I'm trying to accomplish is
1. look through all open workbook for one that has "connect" in the name.
2. look through all open worksheets in the "connect" workbook and name myrange to the sheet that begins with "KPI"

Am I even close?

VBA Code:
    Dim wb As Workbook
    Dim ws As Worksheet
    For Each wb In Workbooks
        If wb.Name Like "*connect*" Then
            For Each ws In Worksheets
                If ws.Name Like "KPI*" Then
                    Set myrange = wb.ws
                End If
            Next ws
        End If
    Next wb
    
    With myrange
        .Range("A1:P20").Select
    End With

Thank you
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I found a solution

VBA Code:
    Dim wb As Workbook
    Dim ws As Worksheet
    For Each wb In Workbooks
        If wb.Name Like "*connect*" Then
            For Each ws In Worksheets
                If ws.Name Like "KPI*" Then
                    Set mypath = Workbooks(wb.Name).Worksheets(ws.Name)
                End If
            Next ws
        End If
    Next wb
    
    With mypath
        .Range("A1:P20").Select
    End With
 
Upvote 0
Alas, my solution did not work. I must have already activated the workbook. I'm still in need of help on this.

Thank you
 
Upvote 0

Forum statistics

Threads
1,224,828
Messages
6,181,217
Members
453,024
Latest member
Wingit77

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top