Vba code to pull data from multiple tabs to master

FGaxha

Board Regular
Joined
Jan 10, 2023
Messages
221
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need help to modify this macro:
I need to pull data from sheet1, sheet2, sheet3 and sheet4 to Master.
Actual code pull data from sheet1 is row is #0.
RowsA to d:
Sub CopyRows()
Application.ScreenUpdating = False
Dim srcWS As Worksheet, desWS As Worksheet, rng As Range
Set srcWS = Sheets("Sheet1")
Set desWS = Sheets("Master")
For Each rng In Range("A2", Range("A" & Rows.Count).End(xlUp))
If WorksheetFunction.CountIf(Range("B" & rng.Row).Resize(, 3), "0") <> 3 Then
With desWS
.Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 4).Value = srcWS.Range("A" & rng.Row).Resize(, 4).Value
End With
End If
Next rng
Application.ScreenUpdating = True
End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Maybe something like this (not tested).
VBA Code:
Sub CopyRows()
    Application.ScreenUpdating = False
    Dim srcWS As Worksheet, desWS As Worksheet, rng As Range
    Dim CellRange As Range

    With ActiveWorkbook
        Set desWS = .Worksheets("Master")

        For Each srcWS In .Worksheets
            Select Case srcWS.Name
            Case "Sheet1", "Sheet2", "Sheet3", "Sheet4"
                With srcWS
                    Set CellRange = .Range("A2", .Range("A" & .Rows.Count).End(xlUp))
                End With

                For Each rng In CellRange
                    If WorksheetFunction.CountIf(Range("B" & rng.Row).Resize(, 3), "0") <> 3 Then
                        With desWS
                            .Cells(.Rows.Count, "A").End(xlUp).Offset(1).Resize(, 4).Value = srcWS.Range("A" & rng.Row).Resize(, 4).Value
                        End With
                    End If
                Next rng
            End Select
        Next srcWS
    End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 1
Solution

Forum statistics

Threads
1,215,743
Messages
6,126,605
Members
449,321
Latest member
syzer

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