Copy between Sheets

hiteshkataria

Board Regular
Joined
Nov 13, 2008
Messages
184
Hi,

I have data in Sheet1 of the Excel sheet. I want to copy the content of Column C & D of Sheet1 into Sheet2 using a macro.

I am able to do using below logic (But i think there is a simple logic):
Get the Last record count of Col C
For i=1 to Last
sheet2.columns(r,c)=sheet1.columns(i,3)
Next i

Since I am using for loop, it takes long time if the data is huge.
Could you please let me know whether my approach is good or there exists a simpler method.
 
Cant seem to get the advanced filter to work and havent time at the mo to get stuck into it.

Maybe a simple sort per below will help? You could then loop through each row and delete any duplicates if you know the criteria.

Code:
Sub CopyColumns()
 
    Application.ScreenUpdating = False
    Application.Calculation = xlCalculationManual
    Dim LastRow As Long
    Dim LastCol As Long
    Dim rngData As Range
 
    'copy columns to sheet 2
    Worksheets("Sheet1").Columns("C:D").Copy
    Worksheets("Sheet2").Columns("C:D").PasteSpecial xlPasteValues
 
    'sort sheet 2
    LastRow = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
    LastCol = Worksheets("Sheet2").Cells(1, Columns.Count).End(xlToLeft).Column
 
    Set rngData = Worksheets("Sheet2").Cells(1, 1).Resize(LastRow, LastCol)
        With Worksheets("Sheet2").Sort
            .SortFields.Clear
 
            With rngData
                .Sort key1:=Range("C1"), order1:=xlAscending, key2:=Range("D1"), order2:=xlAscending, Header:=xlYes
            End With
        End With
 
 
 
 
 
    Application.ScreenUpdating = True
    Application.Calculation = xlCalculationAutomatic
 
End Sub
 
Upvote 0

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".

Forum statistics

Threads
1,223,240
Messages
6,170,951
Members
452,368
Latest member
jayp2104

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