Need Help Modifying Current Macro

cjvenables

Board Regular
Joined
Aug 2, 2011
Messages
65
Hello,

The current macro copies everything from every sheet in a workbook and pastes it to a single sheet. Since there are usually 150K cells on each sheets, and I have 12 sheets (1 for each month), I need to edit this macro to only copy the row if there is something in Column Q. While Columns A-P usually have 150-200K cells, Column Q only has 10-15K cells. Since I run another macro before this, everything in Column Q is sorted from the top, so it has all of the data I want. It would be nice if I could get the effect of selecting Q2, CTRL+SHIFT, arrow key down to the last cell, and then left arrow key over to copy all information. It runs really fast, so hopefully this will not slow it down too much.

Help is greatly appreciated!

Sub Merge()
Dim ws As Worksheet
ActiveSheet.UsedRange.Offset(0).Clear
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then
ws.UsedRange.Copy
Range("A1020000").End(xlUp).Offset(1, 0).Select
Selection.PasteSpecial Paste:=xlValues, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
Selection.PasteSpecial Paste:=xlFormats, Operation:=xlNone, SkipBlanks:= _
False, Transpose:=False
End If
Next
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).
Try

Code:
Sub Merge()
Dim ws As Worksheet, LR As Long
ActiveSheet.UsedRange.Offset(0).Clear
For Each ws In ActiveWorkbook.Worksheets
    If ws.Name <> ActiveSheet.Name Then
        With ws
            LR = .Range("Q" & Rows.Count).End(xlUp).Row
            .Range("A2:Q" & LR).Copy
            Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlValues
            Range("A" & Rows.Count).End(xlUp).Offset(1, 0).PasteSpecial Paste:=xlFormats
        End With
    End If
Next ws
End Sub
 
Upvote 0
LIke this?

Code:
Sub Merge()
Dim ws As Worksheet
Dim LR As Long
ActiveSheet.UsedRange.Offset(0).Clear
Application.ScreenUpdating = False
For Each ws In ActiveWorkbook.Worksheets
If ws.Name <> ActiveSheet.Name Then
With ws
    LR = .Range("Q" & Rows.Count).End(xlUp).Row
    Range(.Cells(2, 1), .Cells(LR, 17)).Copy
End With
With Range("A" & Rows.Count).End(xlUp).Offset(1, 0)
    .PasteSpecial xlValues
    .PasteSpecial xlFormats
End With
End If
Next
Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,603
Messages
6,179,850
Members
452,948
Latest member
UsmanAli786

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