Vba Comp from multiple worksheets based on cell Value

Demer

New Member
Joined
May 5, 2021
Messages
19
Office Version
  1. 365
  2. 2019
  3. 2013
Platform
  1. Windows
Hello, Sorry im not very good with VBA but I need a VBA to search through multiple worksheets and search column c for "Yes" based on c value copy adjacent data in column A from all worksheets and paste those values to a new sheet called "Archive" Note that I have over 40 sheets.







1635104594225.png
 
Try this:
VBA Code:
Sub Filter_Me_Please()
'Modified  10/24/2021  10:13:12 PM  EDT
Application.ScreenUpdating = False
Dim lastrow As Long
Dim C As Long
Dim i As Long
C = 3 ' Column Number Modify this to your need
lastrow = Cells(Rows.Count, C).End(xlUp).Row
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Archive"

For i = 1 To Sheets.Count - 1
With Sheets(i).Cells(1, C).Resize(lastrow)
    .AutoFilter 1, "Yes"
    counter = .Columns(C).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
    lastrowa = Sheets("Archive").Cells(Rows.Count, 1).End(xlUp).Row + 1
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Offset(, -2).Copy Sheets("Archive").Cells(lastrowa, 1)
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
Try this:
VBA Code:
Sub Filter_Me_Please()
'Modified  10/24/2021  10:13:12 PM  EDT
Application.ScreenUpdating = False
Dim lastrow As Long
Dim C As Long
Dim i As Long
C = 3 ' Column Number Modify this to your need
lastrow = Cells(Rows.Count, C).End(xlUp).Row
Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Archive"

For i = 1 To Sheets.Count - 1
With Sheets(i).Cells(1, C).Resize(lastrow)
    .AutoFilter 1, "Yes"
    counter = .Columns(C).SpecialCells(xlCellTypeVisible).Count
    If counter > 1 Then
    lastrowa = Sheets("Archive").Cells(Rows.Count, 1).End(xlUp).Row + 1
        .Offset(1).Resize(.Rows.Count - 1).SpecialCells(xlCellTypeVisible).Offset(, -2).Copy Sheets("Archive").Cells(lastrowa, 1)
    Else
        MsgBox "No values found"
    End If
    .AutoFilter
End With
Next
Application.ScreenUpdating = True
End Sub
Tried this one and it throws the same issue
1635129094679.png


Once I hit Debug it highlights

1635129166235.png
 
Upvote 0
Sorry. It works for me and has worked for others. Hopefully someone else here on the forum will be able to help you.
 
Upvote 0
So the script does nothing?
Except create the new sheet?
My Answer Is This - there doesn't look like there's anything wrong with your code, just wondering if the screenshot provided by the OP is 'typical' of ALL the sheets, specifically Sheet1? The screenshot looks like it might be sheet3?
 
Upvote 0
When you run the script are you running it from the first sheet in your workbook?
 
Upvote 0
My Answer Is This - there doesn't look like there's anything wrong with your code, just wondering if the screenshot provided by the OP is 'typical' of ALL the sheets, specifically Sheet1? The screenshot looks like it might be sheet3?
Thanks for your help. I use this same type script all the time so not sure why it's not working for user.
 
Upvote 0
Solution

Forum statistics

Threads
1,215,746
Messages
6,126,648
Members
449,325
Latest member
Hardey6ix

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