Look through values of 100's of sheets when found copy sheet names to main sheet

adamprocter

Board Regular
Joined
Apr 13, 2015
Messages
53
I am trying to press a button on main sheet that looks across all my sheets and finds the last value in Col I and
When that value is greater than 20 I want to copy that sheet name and paste into my main sheet

I think I'm close but no error but nothing is being pasted...

Code:
    Dim SheetName As Worksheet
    Dim ws1 As Worksheet
    Dim rcMatch As Variant
    Dim LastRow As Long
    
    Set ws1 = ThisWorkbook.Worksheets("Execution Screen (login)")
      For Each SheetName In Worksheets
                            
            If Cells(Rows.Count, "I").End(xlUp).Value > "20" Then
            
            'copy and paste sheetname
            SheetName.Select
           'paste into O6,O8,O10 depending on how many found
            Sheets("Execution Screen (login)").Range("O6").Paste
            
            End If
    
        
    Next SheetName
 
Last edited:

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Can you try something like this.
Code:
    For Each SheetName In Application.Worksheets        If SheetName.Cells(Rows.Count, 9).End(xlUp).Value > 20 Then
            'copy and paste sheetname
            Sheets("The Main Sheet").Range("A6") = SheetName.Name
        End If
    Next SheetName
 
Upvote 0
Try:
Code:
Sub DelRows()
    Application.ScreenUpdating = False
    Dim ws As Worksheet
    Dim bottomI As Long
    Dim x As Long
    x = 6
    For Each ws In Sheets
        If ws.Name <> "Execution Screen (login)" Then
            bottomI = Sheets(ws.Name).Range("I" & Rows.Count).End(xlUp).Row
            If Sheets(ws.Name).Cells(bottomI, "I") > 20 Then
                Sheets("Execution Screen (login)").Range("O" & x) = ws.Name
                x = x + 2
            End If
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
This code assumes that you do not want to look at column I in the "Execution Screen (login)" sheet.
 
Upvote 0
@mumps thanks Looks good am getting Type mismatch on line

If Sheets(ws.Name).Cells(bottomI, "I") > 20 Then
 
Upvote 0
I think this maybe due to the fact I have 2 other sheets i need to ignore as well ?
Code:
If ws.Name <> "Execution Screen (login)" & ?? & ??
 
Upvote 0
Thanks your code worked great once I skipped all the sheets as follows

Code:
For Each ws In ThisWorkbook.Worksheets
    Select Case ws.Name
        Case "Execution Screen (login)", "Sheet 2 (login)", "Sheet 3 (login)"
        Case Else:
                      
            bottomI = Sheets(ws.Name).Range("B" & Rows.Count).End(xlUp).Row
            If Sheets(ws.Name).Cells(bottomI, "I") < 20 Then
                Sheets("Execution Screen (login)").Range("O" & x) = ws.Name
                x = x + 2
            End If
       End Select
    Next ws
 
Upvote 0

Forum statistics

Threads
1,213,535
Messages
6,114,198
Members
448,554
Latest member
Gleisner2

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