Copy data from one sheet to another

Vagelisr

New Member
Joined
Sep 22, 2016
Messages
28
Office Version
  1. 2010
  2. 2007
Platform
  1. Windows
Hi to all

I want to copy only the rows from sheet "data" to sheet "copy_data" using range (i need only until column "m"
I use this but i'm not able to make it work

VBA Code:
Sub Copy_Data()
Dim i, j, LastRow As Long
Dim r As Range
    'Find last row in sheet Data
    With Sheets("Data")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    End With
    
    'Clear Sheet Copy_Data
    With Sheets("Copy_Data")
        .Select
        Selection.Delete Shift:=xlUp
    End With
    
    j = 1
    For i = 2 To LastRow
        If Worksheets("Data").Cells(i, 1).Value <> "" Then
            With Sheets("Data")
                Range(Cells(i, "A"), Cells(i, "M")).Select
            End With
            With Sheets("Copy_Data")
                Range(Cells(j, "A"), Cells(j, "M")).PasteSpecial Paste:=xlValues
            End With
            j = j + 1
        End If
    
    Next i

End Sub

Any help??
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off
How about
VBA Code:
Sub Copy_Data()
Dim i, j, LastRow As Long
Dim r As Range
    'Find last row in sheet Data
    With Sheets("Data")
        LastRow = .Range("A" & .Rows.Count).End(xlUp).Row
    End With
    
    'Clear Sheet Copy_Data
    With Sheets("Copy_Data")
        .Cells.Clear
    End With
    
    j = 1
    For i = 2 To LastRow
        With Worksheets("Data")
            If .Cells(i, 1).Value <> "" Then
               Sheets("Copy_Data").Range("A" & j).Resize(, 13).Value = .Range("A" & i).Resize(, 13).Value
               j = j + 1
            End If
       End With
    Next i

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,641
Messages
6,120,684
Members
448,977
Latest member
dbonilla0331

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