Copy, paste value, to new sheet

jrwrangler

New Member
Joined
Mar 22, 2013
Messages
16
Hello

I have a sheet called lpl data. I need to look over at the cells in column j. If the cell in column j has the words "common stock", then i need to copy that entire row, delete that row, and paste it into another sheet called "______ portfolio". The " _____" will depend on the input provided by the user at the beginning of the macro (already coded that up). Column J is the column to the furthest right in the sheet. The new sheet will start taking this data in cell b3. I need to repeat this process for other values in this column and others so if you could please dumb it all down for me so i could do this on my own, i would really appreciate it. thanks

this is how far i got

Sub Copypaste()

Application.ScreenUpdating = False

lr = Sheet("LPL Data").Range("j" & Rows.Count).End(xlUp).Row
For i = 1 To lr
With Sheet("LPL Data")
If LCase(.Range("j" & i).Value) = "Common Stock" Then
lrr = Sheets("*" & " portfolio").Range("B" & Rows.Count).End(xlUp).Row

Range("J", Selection.End(xlToLeft)).Select
Selection.Copy Sheets("*" & " portfolio").Range("b" & lrr)

End If
End With

Next i

Application.ScreenUpdating = True
 

Excel Facts

Spell Check in Excel
Press F7 to start spell check in Excel. Be careful, by default, Excel does not check Capitalized Werds (whoops)
lrr = Sheets("*" & " portfolio").Range("B" & Rows.Count).End(xlUp).Row

If this line is going to be B3 every time then just say so otherwise you need +1 at the end of the description
so it finds the last used row and then steps one down to paste.
 
Upvote 0
I run the macro and i get "sub or function not defined"
In this line:
lr = Sheet("LPL Data").Range("j" & Rows.Count).End(xlUp).Row

its highlighting the "sheet".
 
Upvote 0
firstly it should say sheets

if you have option explicit you need to dim all your variables

i, lr and Irr
 
Upvote 0
untested:

Application.ScreenUpdating = False
lrr = Sheets("*" & " portfolio").Range("B" & Rows.Count).End(xlUp).Row + 1
lr = Sheet("LPL Data").Range("j" & Rows.Count).End(xlUp).Row
For i = lr to 1 step -1
If LCase(.Range("j" & i).Value) = "Common Stock" Then
Range("j" & i).EntireRow.Copy Destination:=Sheets("*" & "portfolio").Cells(lrr, 2)
Range("j" & i).EntireRow.Delete
lrr = lrr + 1
End If
Next i
Application.ScreenUpdating = True
 
Upvote 0
you should note that the macro runs from bottom to top due to sheets being deleted, I am not sure what this does to the data being transfered.

If it needs to be in top to bottom order it may need to run twice once to copy info once to delete the line
 
Upvote 0
try placing this line just beneath the application.screenupdating = false line

ensure you are on LPL Data sheet and press f8 to step through and ensure it is recognising the portfolio sheet

Sheets("*" & " portfolio").select

did you mean for the gap between the first appostophie and the word Portfolio?
 
Upvote 0
Ya "im out of range" or something. its highlighting the lrr line where i define the variable

I did mean for the gap because there will be a gap between the first word and portfolio
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,849
Members
452,361
Latest member
d3ad3y3

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