Cut and Paste Macro into another sheet

Prashant2082

New Member
Joined
Jun 27, 2011
Messages
6
Hi Everyone,

I am trying to create a macro to identify certain record in one sheet, and cut and paste that record in another sheet.

eg:
Sheet names - Names, John, James, Charlie
Sheet Names: Column A - Sample values - John, James, Charlie

as per my requirement, if i run the macro, it should find the different names in Column A of sheet "Name" and should insert the record in respective sheet.

Could you please advice.

Thanks and Regards,
Prashant
 

Excel Facts

How to show all formulas in Excel?
Press Ctrl+` to show all formulas. Press it again to toggle back to numbers. The grave accent is often under the tilde on US keyboards.
Hi Peter,

Thanks for your time and response.
However, just wanted to highlight, i need to append the data on ongoing basis on existing sheets. So i can not use new sheets.

Please advice.

Thanks and Regards,
Prashant
 
Upvote 0
Perhaps this

Code:
Sub ToNames()
Dim LR As Long, i As Long
With Sheets("Name")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        .Rows(i).Copy Destination:=Sheets(.Range("A" & i).Value).Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
End With
End Sub
 
Upvote 0
Thanks Peter.

But now i am getting error subscript out of range.
I tried to see excel help, but it doesnot look like similar scenario given.

I am relatively new in macro. Could you please advice.

Regards,
Prashant
 
Upvote 0
When that error occurs click the Debug button. Which line of code is highlighted?
 
Upvote 0
Hi Peter,

Its coming on
.Rows(i).Copy Destination:=Sheets(.Range("A" & i).Value).Range("A" & Rows.Count).End(xlUp).Offset(1)

Regards,
Prashant
 
Upvote 0
That means that a sheet with one of your names doesn't exist. Try

Code:
Sub ToNames()
Dim LR As Long, i As Long
With Sheets("Name")
    LR = .Range("A" & Rows.Count).End(xlUp).Row
    For i = 1 To LR
        If Not WorksheetExists(.Range("A" & i).Value) Then Worksheets.Add(After:=Worksheets(Worksheets.Count)).Name = .Range("A" & i).Value
        .Rows(i).Copy Destination:=Sheets(.Range("A" & i).Value).Range("A" & Rows.Count).End(xlUp).Offset(1)
    Next i
End With
End Sub


Function WorksheetExists(WSName As String) As Boolean
On Error Resume Next
WorksheetExists = Worksheets(WSName).Name = WSName
On Error GoTo 0
End Function
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,828
Members
452,946
Latest member
JoseDavid

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