VBA: All Sheets data to Master Sheet (excluding some sheet)

Samantha27

New Member
Joined
Jan 30, 2024
Messages
7
Office Version
  1. 2016
Platform
  1. Windows
Hi Good People,

Okay so I'm having a hard time fixing this code that I came across from my research.. What I wanted to achieve is this..

I have a

MasterSheet - Sheet1-Sheet2-Sheet3-NotesSheet, NoteSheet 2.

I have a macro button in the masterfile sheet that will extract the data from Sheet1-Sheet3 but exclude data from notesheet and notesheet 2.

The masterfile have the same heading of sheet1-sheet3 so I just need to extract the data daily. Up to the next available cell, but not over ride the previous data.

below is my code.. 😭

Please help me achieve this.. I can't stress this enough.. Below is my code. Thank you!!



VBA Code:
Sub CopyRange()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Dim wkbSource As Workbook
    Set wkbDest = ThisWorkbook
    Dim LastRow As Long
    Const strPath As String = "c:\Users\michal\Documents\Macro\"
    ChDir strPath
    strExtension = Dir("*.csv*")
    Do While strExtension <> ""
        Set wkbSource = Workbooks.Open(strPath & strExtension)
        With wkbSource
            LastRow = .Sheets(1).Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
            .Sheets(1).Range("A1:E" & LastRow).Copy wkbDest.Sheets(1).Cells(Rows.Count, "B").End(xlUp).Offset(1, 0)
            .Close savechanges:=False
        End With
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
OK, try the following instead:
VBA Code:
Option Explicit
Sub Copy_Some_Sheets_V3()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, wsM As Worksheet
    Set wsM = Worksheets("Master")
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Master" And ws.Name Like "Note*" = False Then
            If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
                With ws.Range("A1").CurrentRegion
                    .AutoFilter 4, "<>Done"
                    .Offset(1).Resize(.Rows.Count - 1, 3).Copy wsM.Cells(Rows.Count, 1).End(xlUp).Offset(1)
                    .AutoFilter
                End With
            ws.Range("D2:D" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value = "Done"
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Edited
VBA Code:
Option Explicit
Sub Copy_Some_Sheets_V4()
    Application.ScreenUpdating = False
    Dim ws As Worksheet, wsM As Worksheet
    Set wsM = Worksheets("Master")
    
    For Each ws In ThisWorkbook.Worksheets
        If ws.Name <> "Master" And ws.Name Like "Note*" = False Then
            If ws.AutoFilterMode Then ws.AutoFilter.ShowAllData
                With ws.Range("A1").CurrentRegion
                    .AutoFilter 4, "<>Done"
                    If .SpecialCells(xlCellTypeVisible).Address <> .Rows(1).Address Then
                        .Offset(1).Resize(.Rows.Count - 1, 3).Copy wsM.Cells(Rows.Count, 1).End(xlUp).Offset(1)
                    End If
                    .AutoFilter
                End With
            ws.Range("D2:D" & ws.Cells(Rows.Count, "A").End(xlUp).Row).Value = "Done"
        End If
    Next ws
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,867
Messages
6,175,062
Members
452,610
Latest member
Sherijoe

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