Copy and Paste

Paleo

New Member
Joined
Jan 4, 2005
Messages
43
I have a problem. I need to look upon a worksheet and find cells that have a "JF" expression on them. After that I need to select their hole row, cut them, create a new worksheet and paste the cutted cells on it.

I did it till the cut and sheets.add phase but I am not being able to paste the content.

May someone help me please?????
 

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.
Hello Paleo, welcome to the board!!


So when a cell has the value JF, copy/paste whole row to a new worksheet, delete the original row? Is that the only value in a cell, "JF"? If not, can you give examples?
 
Upvote 0
Hi Zack,

yes "JF" is the only value in the cell. I tryied like this:

Code:
RowNumber = 2 
For Each Cell in Columns("A:A") 
   If ActiveCell = "NJ" Then 
      ActiveCell.EntireRow.Copy Destination:=Sheets("One").Range("A" & RowNumber) 
      RowNumber = RowNumber + 1 
   End If 
Next

but didnt work out either.

May you help me please?
 
Upvote 0
Close. Although I'm not sure if you are looking for JF or NJ?? This looks for NJ in any cell in column A of the activesheet...


<font face=Tahoma New><SPAN style="color:#00007F">Option</SPAN> <SPAN style="color:#00007F">Explicit</SPAN>

<SPAN style="color:#00007F">Sub</SPAN> fooTest()
    <SPAN style="color:#00007F">Dim</SPAN> RowNumber <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">Long</SPAN>, Cell <SPAN style="color:#00007F">As</SPAN> Range, Rng <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Set</SPAN> Rng = Range("A65536").End(xlUp)
    RowNumber = 2
    <SPAN style="color:#00007F">If</SPAN> Rng.Row < 2 <SPAN style="color:#00007F">Then</SPAN> <SPAN style="color:#00007F">Exit</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
    Application.DisplayAlerts = <SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">For</SPAN> <SPAN style="color:#00007F">Each</SPAN> Cell <SPAN style="color:#00007F">In</SPAN> Range("A1", Rng)
        <SPAN style="color:#00007F">If</SPAN> Cell.Value = "NJ" <SPAN style="color:#00007F">Then</SPAN>
            Cell.EntireRow.Copy Sheets("One").Range("A" & RowNumber)
            Cell.EntireRow.Delete
            RowNumber = RowNumber + 1
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">If</SPAN>
    <SPAN style="color:#00007F">Next</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
    Application.DisplayAlerts = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


Does this help?
 
Upvote 0
Gee Zack, :pray:

this was EXACTLY what I needed. I THANK YOU, VERY MUCH. You saved my day!! :pray:
 
Upvote 0
Well I am back here, :cry:

the problem wasnt solved yet. It is working but in a strange way. It copies some rows (not all) and deletes some rows also (not all also). Yes, it deletes the rows it has copied.

I tried breaking the routines apart. One for copy purpose and another for deletion but simply got the same result. Thought it was a memory issue and changed from a 512 Mb machine to a 1 Gb machine. Same result.

So now, may someone help me please???? :rolleyes:
 
Upvote 0
I would hesitate a guess right off that the cell value does not match that of the 'hardcoded' VBA value ("NJ"). Probably due to leading/trailing spaces. You can perform a simple test for this by changing this line of code ...
Code:
        If Cell.Value = "NJ" Then

.. with this line of code ...
Code:
        If UCase(Trim(Cell.Value)) = "NJ" Then

It should look at a non-case sensitive trimmed (no leading/trailing spaces) value and test against "NJ". Does that make a difference? If not, post a small (but various) representation of your data using the HTML Maker.
 
Upvote 0
:rolleyes: Hi Zack,

well, didnt work again. Same old problem. I am posting my code here:
nov.xls
BCDE
18153766OPCIF64485
19112878NCCIF14129
20151703OPCIF14827
21151703OPCIF14827
22151703OPCIF14827
23151703OPCIF14827
24151703OPCIF14827
25151703OPCIF14827
26154788OPCIF14827
27112333NCCIF14827
28157863OPCIF64485
29157863OPCIF64485
30157863OPCIF64485
31151674OPCIF64485
32153766OPCIF64485
33151640OPCIF14129
34112878NCCIF14129
35112878NCCIF14129
36112878NCCIF14129
37112882NCCIF14129
38112882NCCIF14129
39112878NCCIF14129
40153684OPCIF14129
41157063OPCIF14129
42112860NCCIF14129
43112860NCCIF14129
44112860NCCIF14129
45112862NCCIF14129
46112862NCCIF14129
47112862NCCIF14129
nov
 
Upvote 0
I had to change the text from "NJ" to "NC" but thats not the problem, just a little adjust.

Please may you help me? :rolleyes: :rolleyes:
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,300
Members
449,095
Latest member
Chestertim

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