![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Why doesn't work this macro?
I receive an error message on the line : Range("A5").PasteSpecial This is my macro : Sub Filter() currentworkbook = ActiveWorkbook.Name currentsheet = ActiveSheet.Name Columns("L:L").Select Selection.autofilter Field:=1, Criteria1:="1" Range("A5:" & Range("K65536").End(xlUp).Address).Copy Workbooks.OpenText Filename:="G:Mijn documentenMap1.xls" Sheets("Blad1").Select Range("A5").PasteSpecial Workbooks(currentworkbook).Sheets(currentsheet).Activate Selection.autofilter Range("A1").Select End Sub Many thanks for help. |
|
|
|
|
|
#2 |
|
Board Regular
Join Date: Feb 2002
Location: Stockton, California
Posts: 281
|
Hmm...this code worked for me. Maybe theres something wrong with your cells? Is range a5 merged with any others in the workbook you opened?
|
|
|
|
|
|
#3 | |
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Quote:
Maybe I may ask you another question: I want to clear all in the sheet Blad1,before pastespecial.Is this possible,or do I manuelly clear this before pastespecial? Many thanks for your time. |
|
|
|
|
|
|
#4 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
insert this line when blad1 is selected
Cells.ClearContents regards Tommy |
|
|
|
|
|
#5 | |
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Quote:
Yes the cells are cleared before paste,but it doesn't work,maybe the copied cells have an interiorcolor.Those colors are not cleared.Can I add any code to also clear those colors,before paste? Thanks |
|
|
|
|
|
|
#6 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
Yes Verluc, no problem.
Cells.Clear regards Tommy |
|
|
|
|
|
#7 | |
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Quote:
When I add the code and run the macro,I receive the error 1004 "Methode PasteSpecial of class range ..." I have a yellow color on the line: Range("A1").PasteSpecial Have you any idea? Thanks |
|
|
|
|
|
|
#8 | ||
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Quote:
Have you any idea about this erro message? Many thanks |
||
|
|
|
|
|
#9 | |||
|
Board Regular
Join Date: Mar 2002
Posts: 1,288
|
Quote:
When I delete the instruction Cells.Clear,then the macro works. With the instruction Cells.Clear,the macro doesn't work. Any Idea? |
|||
|
|
|
|
|
#10 |
|
Board Regular
Join Date: Feb 2002
Location: Guderup, Denmark
Posts: 287
|
Hi verluc.
I've changed your macro a couple of places. Now it seems to run well. Sub Filter() currentworkbook = ActiveWorkbook.Name currentsheet = ActiveSheet.Name Columns("L:L").Select Selection.AutoFilter Field:=1, Criteria1:="1" Set kopi = Range("A5:" & Range("K65536").End(xlUp).Address) Workbooks.OpenText Filename:="G:\Mijn documenten\Map1.xls" Cells.Clear kopi.Copy Range("A5").Select ActiveSheet.Paste Workbooks(currentworkbook).Worksheets(currentsheet).Activate Selection.AutoFilter Range("A1").Select End Sub |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|