member23

New Member
Joined
Apr 20, 2015
Messages
13
Hello to you all

My question is simple but i just can't find something that works. This code is to get data from one sheet to another upon opening the workbook. The thing is that i want it to get data from multiple sheets not just one, so how could i get that number of sheets inside the code? The sheet with data is Sheet 3 (in which the rest have to be added) and Sheet 2 is where data should go. Thanks a lot for your time guys..






Private Sub Workbook_Open()
Dim i, LastRow

LastRow = Sheets("Sheet3").Range("A" & Rows.Count).End(xlUp).Row
Sheets("Sheet2").Range("A2:I500").ClearContents
For i = 2 To LastRow
If Sheets("Sheet3").Cells(i, "E").Value = "" Then
Sheets("Sheet3").Cells(i, "E").EntireRow.Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
End If
Next i
End Sub
 

Excel Facts

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
UNTESTED
Code:
Private Sub Workbook_Open()
Dim i As Long, LastRow As Long, ws As Worksheet
Sheets("Sheet2").Range("A2:I500").ClearContents
For Each ws In Worksheets
    If ws.Name <> ("Sheet2") Then
        ws.Activate
        LastRow = ws.Range("A" & Rows.Count).End(xlUp).Row
            For i = 2 To LastRow
                If ws.Cells(i, "E").Value = "" Then
                    Rows(i).Copy Destination:=Sheets("Sheet2").Range("A" & Rows.Count).End(xlUp).Offset(1)
                End If
            Next i
    End If
Next ws
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,073
Messages
6,128,637
Members
449,461
Latest member
kokoanutt

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