Microsoft Excel - Copy paste methods

Asked By Jimmy Laki
02-Feb-10 06:41 AM

Hello,

 

I am having some problems trying to find the mistake I am making with the following code. I wrote this code to filter some data in field 13 copy that data and paste it into a a sheet called Brokered trades and then go back to today`s sheet and filter on field 12 and delete this criteria. With the remaining data I want to copy what is left and paste to brokered trades also.

 

I have this code split here into two sections Section 1 is giving me the problem on line 'ActiveCell.Offset(1, 0).Paste .

 Section 2 is a replica of the first part of the code and works fine. Any pointers would be greatly appreciated

 

Dim lastrow As Integer
Dim RNG As Range
Dim Numb_row As Integer
Dim RNGA As Range
Dim RNGA1 As Range
Dim sheetname As String

    SECTION 1


    Application.ScreenUpdating = False
    Application.CutCopyMode = False

     lastrow = Range("L1").End(xlDown).Row
     sheetname = Format(Date, "mmmdd")
     Sheets(sheetname).Range("A1:Q" & lastrow).Select
   
     'Selection.AutoFilter
     'Selection.AutoFilter Field:=13, Criteria1:="OSE", Operator:=xlAnd
     'Set RNGA = Sheets(sheetname).Range("A1:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
     'Sheets(sheetname).Range("A1:Q" & lastrow).Offset(1, 0).Copy
     'Selection.AutoFilter
     
     'Sheets("brokered trades").Select
     'Cells(Rows.Count, 1).End(xlUp).Select
     'ActiveCell.Offset(1, 0).Paste

      Section 2


     Sheets(sheetname).Range("A1:Q" & lastrow).Select
     Selection.AutoFilter
     Selection.AutoFilter Field:=12, Criteria1:="JPY", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="AUD", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="ZAR", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="CNY", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="NZD", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter
     Set RNG = Sheets(sheetname).Range("L1:L" & Range("L" & Rows.Count).End(xlUp).Row)
     Numb_row = RNG.SpecialCells(xlVisible).Count - 1
     MsgBox "Count  " & Numb_row & " broker trades to check"
     Set RNGA1 = Sheets(sheetname).Range("A1:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
     Sheets(sheetname).Range("A1:Q" & lastrow).SpecialCells(xlCellTypeVisible).Offset(1, 0).Copy
     Sheets("brokered trades").Select
     Cells(Rows.Count, 1).End(xlUp).Select
     ActiveCell.Offset(1, 0).PasteSpecial
     Columns("A:Q").EntireColumn.AutoFit

  Jonathan VH replied to Jimmy Laki
02-Feb-10 07:25 AM

What is the error message or symptom of your "problem?"

Please repost your code without commenting out the lines you want.

  Jimmy Laki replied to Jonathan VH
02-Feb-10 07:35 AM
Dim lastrow As Integer
Dim RNG As Range
Dim Numb_row As Integer
Dim RNGA As Range
Dim RNGA1 As Range
Dim sheetname As String

   
    Application.ScreenUpdating = False
    Application.CutCopyMode = False

     lastrow = Range("L1").End(xlDown).Row
     sheetname = Format(Date, "mmmdd")
     Sheets(sheetname).Range("A1:Q" & lastrow).Select 
    
     Selection.AutoFilter 
     Selection.AutoFilter Field:=13, Criteria1:="OSE", Operator:=xlAnd 
     Set RNGA = Sheets(sheetname).Range("A1:Q" & Range("Q" & Rows.Count).End(xlUp).Row) 
     Sheets(sheetname).Range("A1:Q" & lastrow).Offset(1, 0).Copy 
     Selection.AutoFilter 
     Sheets("brokered trades").Select 
     Cells(Rows.Count, 1).End(xlUp).Select 
     ActiveCell.Offset(1, 0).Paste
     Sheets(sheetname).Range("A1:Q" & lastrow).Select
     Selection.AutoFilter
     Selection.AutoFilter Field:=12, Criteria1:="BNPAFRA", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="PARBPAR", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="BPCMTYO", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="STABPAR", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter Field:=12, Criteria1:="STASPAR", Operator:=xlAnd
     Selection.Offset(1, 0).Delete Shift:=xlUp
     Selection.AutoFilter
     Set RNG = Sheets(sheetname).Range("L1:L" & Range("L" & Rows.Count).End(xlUp).Row)
     Numb_row = RNG.SpecialCells(xlVisible).Count - 1
     MsgBox "Count  " & Numb_row & " broker trades to check"
     Set RNGA1 = Sheets(sheetname).Range("A1:Q" & Range("Q" & Rows.Count).End(xlUp).Row)
     Sheets(sheetname).Range("A1:Q" & lastrow).SpecialCells(xlCellTypeVisible).Offset(1, 0).Copy
     Sheets("brokered trades").Select
     Cells(Rows.Count, 1).End(xlUp).Select
     ActiveCell.Offset(1, 0).PasteSpecial
     Columns("A:Q").EntireColumn.AutoFit
  Jimmy Laki replied to Jimmy Laki
02-Feb-10 07:36 AM

sorry I posted before I could write a msg. The error message is saying object required or does not support this method. It seems strange because I have the same code further down which works fine.

 

JL

  Jonathan VH replied to Jimmy Laki
02-Feb-10 07:42 AM
And what is the error message or symptom of the "problem" with the Paste method?
  Jonathan VH replied to Jimmy Laki
02-Feb-10 07:52 AM

If you reply to yourself, you're the only one who gets emailed...

I'm not going to attempt to parse that interesting code.  As you seem to have created much of it by using the macro recorder, try recording again the steps you are automating and look at the code that creates.  I suspect the problem has something to do with invoking the Copy method and then filtering and selecting before finally using the Paste method.

  Jimmy Laki replied to Jonathan VH
07-Feb-10 12:23 AM
Thank you, Understood.  I didn`t record the code but wrote it using help from a text book. I will follow your suggestion and hopefully find where I am going wrong. Thank you once again for the help. JL
  Jonathan VH replied to Jimmy Laki
07-Feb-10 06:54 AM
If that code is from a textbook, you need to get a different textbook.
Create New Account
help
2007 excel autofilter change back to 2003 autofilter? Excel Is it possible to change the 2007 autofilter back to like the 2003 autofilter worked? Excel Miscellaneous Discussions Microsoft (1) I see you have a response to one of your other posts - - in a
Excel copy only visible rows from autofilter Excel Excel 2007 - This was working in a different spreadsheet, however in this new spreadsheet I am performing a filter using the autofilter function. Then I only want to copy and paste what was filtered into a new it wasn't filtered. I only want to paste the filtered rows. Any ideas? Thanks! Excel Miscellaneous Discussions Excel 2007 (1) Excel (1) Worksheet (1) Workbook (1) Duketter (1) Modifies (1) Marquee (1) Ants (1) Deleting or
AutoFilter Excel Hallo zusammen AutoFilter grösser 1000 Zeilen? Wie? Danke! Thomas Excel - German Discussions Microsoft Excel (1) Excel 2007 (1) Vista (1) VBA (1) CarloAndreas (1) AndresJa (1) drav@bluewin.ch schrieb: Einfach nach dem eigentlichen Wert in der Original-Spalte. Mit freundlichen Grüssen Thomas Ramel - - - MVP für Microsoft-Excel - [Vista Ultimate SP-1 / xl2007 SP-1] Hallo Thomas Ich habe eine grosse Excel
How do you insert drop down values at the top of a column in Excel Excel Excel Miscellaneous Discussions AutoFilter (1) Excel 2003 (1) Excel (1) XP (1) F0F3719DC95D (1) Pebunn (1) If you want to set up an AutoFilter Try this: Select the data list From the Excel Main Menu: That will put drop-down arrows at the top of each column that
how to use the function sorting in excel Excel can you help me on how to use the function sorting in excel. thank you Excel New Users Discussions Microsoft Excel (1) Excel (1) Max (1) Xdemechanik (1) Accomadate (1) Excel2003 (1) For a good start, suggest you try Excel's help, Click Help> Microsoft Excel Help, search for: sorting The fundamentals are all there