Excel Macro VBA Copy Paste Between Sheets

Melpp

New Member
Joined
May 3, 2011
Messages
29
Hi! I am a new user with Excel Macros and VBA. I need to copy some data from one main worksheet into individual worksheets based on the value set in one of the columns. Here is the code I am currently using. The code does not run and stops at the line "Worksheets("Sheet 1").Range("Cells(i,1)").Offset(0, 7).Selection.Copy" Please help me.

Worksheets.Add().Name = " Anterior"

For i = 5 To Last_Row + 3
If Worksheets("Sheet 1").Cells(i, 2).Value = "Anterior" Then
Worksheets("Sheet 1").Range("Cells(i,1)").Offset(0, 7).Selection.Copy
Worksheets("Anterior").Range("Cells(i,2)").Paste

End If
Next i
 
Hi Melpp.

As Peter shown you, I think the main problem is you created sheet with name " Anterior" (with one leading space), and you try to copy it to sheet with name "Anterior" (with no leading space).

to make it more clearer, you can change the sheet name to other name (as anterior might confuse with data in cell(i,2).

best regards,
AnuG
 
Upvote 0

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Hey, I found my mistake. Now I want to copy an entire row (or a few cells) rather than a single cell. How would I go about that?
 
Upvote 0
Maybe like this

Rich (BB code):
For i = 5 To Last_Row + 3
    If Worksheets("Sheet1").Cells(i, 2).Value = "Anterior" Then
        Worksheets("Sheet1").Cells(i, 1).Resize(0, 7).Copy Destination:=Worksheets(" Anterior").Cells(i, 2)
    End If
Next i
 
Upvote 0

Forum statistics

Threads
1,224,606
Messages
6,179,866
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