Re: Filtered list
- From: "Khalil Handal" <khhandal@xxxxxxxxxx>
- Date: Fri, 10 Mar 2006 02:05:50 +0200
Hi,
Thanks for what you offer, I will try it. Just want you know it is going to
be pasted in a new empty worksheet.
Khalil
"Dave Peterson" <petersod@xxxxxxxxxxxxxxxx> wrote in message
news:44109EE3.75C5EDAE@xxxxxxxxxxxxxxxxxxx
Since your code depends on what's selected, it's difficult to guess where
things
should be pasted.
But this may give you an idea. I didn't test it, but it did compile:
Option Explicit
Sub testme()
Dim RngToFilter As Range
Dim RngToCopy As Range
Dim DestWks As Worksheet
Dim DestCell As Range
Dim LastRow As Long
With ActiveSheet
.Unprotect Password:="hithere"
'turn off any existing filter
.AutoFilterMode = False
Set RngToFilter = .Range("ei16", .Cells(.Rows.Count,
"EI").End(xlUp))
RngToFilter.AutoFilter Field:=1, Criteria1:="<>"
If RngToFilter.Cells.SpecialCells(xlCellTypeVisible).Count = 1 Then
'no visible rows in filter.
Set RngToCopy = Nothing
Else
With RngToFilter
Set RngToCopy = .Resize(.Rows.Count - 1, 1).Offset(1, 0) _
.Cells.SpecialCells(xlCellTypeVisible)
End With
End If
.AutoFilterMode = False
.Protect Password:="hithere"
End With
If RngToCopy Is Nothing Then
MsgBox "Nothing filtered--quitting"
Exit Sub
End If
Set DestWks = Nothing
On Error Resume Next
Set DestWks = Workbooks("w_v.xls").Worksheets("sheet2")
On Error GoTo 0
If DestWks Is Nothing Then
Set DestWks = Workbooks.Open("H:\W_V.xls").Worksheets("sheet2")
End If
With DestWks
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row + 1
Set DestCell = .Cells(LastRow, "A")
End With
RngToCopy.EntireRow.Copy _
Destination:=DestCell
Application.CutCopyMode = False
End Sub
Khalil Handal wrote:
Hi, I hope that some one can help!
I want to take a certain range of cells in the file "HCP_2005_upgrade"
and
filter so as to select all the cells that are not empty.
Then select all the rows for these cells and copy them to a new workbook
"W_V" in "sheet2". I have the following code.
Three problems:
1- When copying to the new workbook I did not have the
same
column width. What should I do in order to have the same column width?
2- What code do I need to add, and where, so as to let
the
macro automatically find the last row that is not empty (particularly in
column B). Select only the filtered range.
3- My sheet is protected. The auto filter only works for
unprotected sheets. How can I overcome this problem or go around it.
(i.e.
to do filtration for protected sheets).
The code is:
Sub Macro1()
Range("EI16:EI159").Select
Selection.AutoFilter
Selection.AutoFilter Field:=1, Criteria1:="<>"
Rows("1:44").select --à (what code do I need so that the macro do this
automaticaly since it changes often).
Workbooks.Open Filename:="H:\W_V.xls"
Sheet("Sheet2").Select
Selection.PasteSpecial Paste:x1PasteColumnWidths, Operation:=x1None,_
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste
Range("E7").Select
ActiveWindow.FreezePanes=True
Windows("HCP_2006_Upgrade.xls").Activate
Range("A16").Select
Application.CutCopyMode=False
Selection.AutoFilter
Range("A1").Select
End Sub
Khalil
--
Dave Peterson
.
- Follow-Ups:
- Re: Filtered list
- From: Dave Peterson
- Re: Filtered list
- References:
- Filtered list
- From: Khalil Handal
- Re: Filtered list
- From: Dave Peterson
- Filtered list
- Prev by Date: Re: Highlight rows with certain condition in some cells
- Next by Date: Re: Highlight rows with certain condition in some cells
- Previous by thread: Re: Filtered list
- Next by thread: Re: Filtered list
- Index(es):
Relevant Pages
|