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?????
 
Hi Zack,

its a lot faster but I am getting in an error also.

It tells me "no cell found".

Then I change from "Range(filterRng.Cells(2, 1)" to "Range(filterRng.Cells(1, 1)" and no error but nothing happens too :cry:

After that I tried to change from "filterRng.AutoFilter field:=2" to "filterRng.AutoFilter field:=1". It tells me the copy method from range class failed.

But the copy worked just fine, simply didnt delete the cells after copy.

I am pasting my plan and my code here for you to see.
Paleo2.xls
ABCD
1TypeOrderItemValue
2OP14642051747S1390
3OP14642051748S1390
4OP140851863393M938476,91
5OP111301MIE400MEXE01225
6OP111301CPE275ADVE011254
7OP111301CPE283ADVE01842,4
8OP111301CPE292ADVE01416
9OP111301CPE299ADVE01607,2
10OP111301MII400BE012071,3
11OP111301MII5300E01730,4
12OP111301MOI5300E01172
13NC141293456,51
14OP6448501107245/00092,94
15OP6448501112916/000222
16OP6448501112916/000148
17OP6448501112916/000148
18NC1412901119241/000108,36
Base
<font face=Courier New>    Range("A1").EntireRow.Copy Sheets(Nova).Range("A1")
    
    <SPAN style="color:#007F00">' Filter NC</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> filterRng<SPAN style="color:#00007F">As</SPAN> Range, copyRng<SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Set</SPAN> filterRng = Range("A1", Range("K65536").End(xlUp))
    filterRng.AutoFilter field:=1, Criteria1:="=NC"
    filterRng.SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A1")
    Range(filterRng.Cells(1, 1), filterRng.Cells(filterRng.Rows.Count, _
        filterRng.Columns.Count)).SpecialCells(xlCellTypeVisible).Delete
    filterRng.AutoFilter
    Application.CutCopyMode =<SPAN style="color:#00007F">False</SPAN>
    
    Sheets(Nova).Activate
    Range("A1:F21").Select</FONT>
 
Upvote 0

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
Okay, try this one ...


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

<SPAN style="color:#00007F">Sub</SPAN> TransferMMplease()
    <SPAN style="color:#007F00">' Filter NC</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> filterRng <SPAN style="color:#00007F">As</SPAN> Range, copyRng <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Set</SPAN> filterRng = Range("A1", Range("K65536").End(xlUp))
    Application.DisplayAlerts = <SPAN style="color:#00007F">False</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
    filterRng.AutoFilter field:=1, Criteria1:="=NC"
    filterRng.SpecialCells(xlCellTypeVisible).Copy Sheets("Nova").Range("A1")
    filterRng.SpecialCells(xlCellTypeVisible).Delete
    filterRng.Cells(1).EntireRow.Insert
    Sheets("Nova").Range("1:1").Copy Sheets("Base").Range("1:1")
    <SPAN style="color:#007F00">'Sheets("Base").Cells.AutoFilter</SPAN>
    Application.DisplayAlerts = <SPAN style="color:#00007F">True</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>


We'll get it. ;)
 
Upvote 0
Hi Zack,

stills the same. I got an error:

Copy method from class range failed on line

Code:
filterRng.SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A1")

Nova is a variable name thats why its without brackets.

So, now what may we do???
 
Upvote 0
Hi Zack,

here is it.

<font face=Courier New>    <SPAN style="color:#00007F">While</SPAN> (Len(nommes) > 3) <SPAN style="color:#00007F">Or</SPAN> nommes = ""
        nommes = InputBox("Type month's name with 3 characters", "Report Month", _
            "jan, feb, mar, apr, mai, jun, jul, aug, sep, oct, nov, dec")
    <SPAN style="color:#00007F">Wend</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
    <SPAN style="color:#00007F">Dim</SPAN> aNome <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    aNome = "can_" & LCase(nommes)
    Sheets(ActiveSheet.Name).Name = aNome
    Sheets.Add
    <SPAN style="color:#00007F">Dim</SPAN> Nova <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    Nova = "NC_" & LCase(nommes)
    Sheets(ActiveSheet.Name).Name = Nova
    Sheets(aNome).Activate
    Range("A1").EntireRow.Copy Sheets(Nova).Range("A1")
    <SPAN style="color:#00007F">Dim</SPAN> filterRng <SPAN style="color:#00007F">As</SPAN> Range, copyRng <SPAN style="color:#00007F">As</SPAN> Range
    <SPAN style="color:#00007F">Set</SPAN> filterRng = Range("A1", Range("K65536").End(xlUp))
    <SPAN style="color:#00007F">With</SPAN> filterRng
        .AutoFilter field:=1, Criteria1:="=NC"
        .SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A2")
        .SpecialCells(xlCellTypeVisible).Delete
        .Cells(1).EntireRow.Insert
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    Sheets(Nova).Range("1:1").Copy Sheets(aNome).Range("1:1")
    Sheets(Nova).Activate
</FONT>
 
Upvote 0
Try this ...


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

<SPAN style="color:#00007F">Sub</SPAN> TestForMrE()
    <SPAN style="color:#00007F">Dim</SPAN> aNome <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, Nova <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>, filterRng <SPAN style="color:#00007F">As</SPAN> Range, nommes <SPAN style="color:#00007F">As</SPAN> <SPAN style="color:#00007F">String</SPAN>
    <SPAN style="color:#00007F">While</SPAN> (Len(nommes) > 3) <SPAN style="color:#00007F">Or</SPAN> nommes = ""
        nommes = InputBox("Type month's name with 3 characters", "Report Month", _
            "jan, feb, mar, apr, mai, jun, jul, aug, sep, oct, nov, dec")
    <SPAN style="color:#00007F">Wend</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">False</SPAN>
    Application.DisplayAlerts = <SPAN style="color:#00007F">False</SPAN>
    aNome = "can_" & LCase(nommes)
    Nova = "NC_" & LCase(nommes)
    ActiveSheet.Name = aNome
    Sheets.Add
    ActiveSheet.Name = Nova
    <SPAN style="color:#00007F">With</SPAN> Sheets(aNome)
        <SPAN style="color:#007F00">'.Range("A1").EntireRow.Copy Sheets(Nova).Range("A1")</SPAN>
        <SPAN style="color:#00007F">Set</SPAN> filterRng = .Range("A1", .Range("D65536").End(xlUp))
        <SPAN style="color:#00007F">With</SPAN> filterRng
            .AutoFilter field:=1, Criteria1:="=NC"
            .SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A2")
            .SpecialCells(xlCellTypeVisible).Delete
            .Cells(1).EntireRow.Insert
        <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
        Sheets(Nova).Range("1:1").Copy .Range("1:1")
    <SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">With</SPAN>
    Sheets(Nova).Activate
    Application.DisplayAlerts = <SPAN style="color:#00007F">True</SPAN>
    Application.ScreenUpdating = <SPAN style="color:#00007F">True</SPAN>
<SPAN style="color:#00007F">End</SPAN> <SPAN style="color:#00007F">Sub</SPAN>
</FONT>
 
Upvote 0
Hi Zack,

the same old error 1004 at this line:

.SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A2")
:rolleyes:
 
Upvote 0
Actually,

.SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A2")

must be

.SpecialCells(xlCellTypeVisible).Copy Sheets(Nova).Range("A1")

to avoid letting row 1 blank
 
Upvote 0
I commented out the copy line that you had. The SpecialCells copies headings over, so it's one or the other. Are you using the code I posted?
 
Upvote 0

Forum statistics

Threads
1,215,926
Messages
6,127,731
Members
449,401
Latest member
TTXS

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