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
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Welcome to the board.

You don't want to select the range you're copying. Try the below.

Code:
Worksheets.Add().Name = " Anterior"

For i = 5 To Last_Row + 3
If Worksheets("Sheet 1").Cells(i, 2).Value = "Anterior" Then Worksheets("Sheet 1").Cells(i,1).Offset(0, 7).Copy Destination:= Worksheets("Anterior").Range("Cells(i,2)")
Next i
 
Upvote 0
Try

Code:
For i = 5 To Last_Row + 3
    If Worksheets("Sheet1").Cells(i, 2).Value = "Anterior" Then
        Worksheets("Sheet1").Cells(i, 1).Offset(0, 7).Copy Destination:=Worksheets("Anterior").Cells(i, 2)
    End If
Next i
 
Upvote 0
Unfortunately, the code still does not run with either of those solutions. Any other advice?
 
Upvote 0
Do you get an error? If so click Debug - which line of code is highlighted?
 
Upvote 0
Are you sure that at least one of the cells in column B of sheet 1 contain the word "Anterior" (without any leading/trailing spaces)?
 
Upvote 0
You need a leading space in the destination sheet name

Rich (BB code):
For i = 5 To Last_Row + 3
    If Worksheets("Sheet1").Cells(i, 2).Value = "Anterior" Then
        Worksheets("Sheet1").Cells(i, 1).Offset(0, 7).Copy Destination:=Worksheets(" Anterior").Cells(i, 2)
    End If
Next i
 
Upvote 0
Thanks! It no longer says there is an error. The problem is that it doesnt actually copy the values/range into the new sheet. Not sure why. Any ideas?
 
Upvote 0
Are you sure that column B contains exactly (and only) the word Anterior and that there is something to copy in column H?
 
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