VBA - paste only non empty cells from multiple sheets in the next empty row on a different/master sheet

smide

Board Regular
Joined
Dec 20, 2015
Messages
162
Office Version
  1. 2016
Platform
  1. Windows
Hello.


In Sheet1,2,3,4 and Sheet5 of my Workbook I have a data stored in column C (on all sheets). I need to copy only non empty cells from all sheet's (column C) into column D of my master sheet (Sheet6) in the next empty row eg. without empty cells.
All those five sheets (as well as master sheet) have a header in row 1, and I don't want to copy text from that header.


The problem is also in the fact that my data on those five sheets could start from any row. Search area in column C: from C2 to C700 per sheet.
Empty cells in column C of those sheets could contain formula like: =if(A2="","",B2).


This is what I want to do.


example.

Sheet1

ABC
1Header1
2
32
44
57
6

<tbody>
</tbody>

Sheet2

ABC
1Header2
2
3
4
58
60
76
8
9

<tbody>
</tbody>


Sheet3

ABC
1Header3
2
3
418
519
6

<tbody>
</tbody>


Sheet4

ABC
1Header4
2
3
4
5
6
7
8
9
10
1134
1245
13
14

<tbody>
</tbody>

Sheet5
ABC
1Header5
2
3
4
596
6105

<tbody>
</tbody>

Sheet6 (master sheet - after Macro run)

ABCD
1Header
22
34
47
58
60
76
818
919
1034
1145
1296
13105
14...
15...

<tbody>
</tbody>
 
Last edited:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Hello.


In Sheet1,2,3,4 and Sheet5 of my Workbook I have a data stored in column C (on all sheets). I need to copy only non empty cells from all sheet's (column C) into column D of my master sheet (Sheet6) in the next empty row eg. without empty cells.
All those five sheets (as well as master sheet) have a header in row 1, and I don't want to copy text from that header.


The problem is also in the fact that my data on those five sheets could start from any row. Search area in column C: from C2 to C700 per sheet.
Empty cells in column C of those sheets could contain formula like: =if(A2="","",B2).

Try this:
Code:
Sub a1013344a()

Dim ws As Worksheet, ws6 As Worksheet
Dim ra As Long, rb As Long
    Application.ScreenUpdating = False
Set ws6 = Sheets("Sheet6")
For Each ws In Worksheets
    If UCase(ws.name) <> UCase("Sheet6") Then
        With ws
        ra = .Range("C" & Rows.count).End(xlUp).row
        rb = ws6.Range("D" & Rows.count).End(xlUp).row
        ws6.Range(ws6.Cells(rb + 1, "D"), ws6.Cells(rb + ra - 1, "D")).Value = _
        ws.Range(ws.Cells(2, "C"), ws.Cells(ra, "C")).Value
        End With
    End If
Next
On Error Resume Next
With ws6.Range("D2", ws6.Cells(Rows.count, "D").End(xlUp))
.SpecialCells(xlCellTypeBlanks).Rows.Delete
.SpecialCells(xlConstants, xlErrors).Rows.Delete
End With
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,216,075
Messages
6,128,668
Members
449,463
Latest member
Jojomen56

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