Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy after Autofilter with no rows found

I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copy after Autofilter with no rows found

Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,302
Default Copy after Autofilter with no rows found

Hi Jeff,

field:=2, _


Should be:

field:=3, _


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds
the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy after Autofilter with no rows found


--
Jeff B


"Norman Jones" wrote:

Hi Jeff,

field:=2, _


Should be:

field:=3, _


---
Regards,
Norman



"Norman Jones" wrote in message
...
Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds
the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B





Thanks, I'll give it a try....

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Copy after Autofilter with no rows found

Thanks, that helped my out of my "quirk."

--
Jeff B





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Copy after Autofilter with no rows found

Hi Norman,
I have a very similar problem. I use the following piece of code (I don't
repeat here the declarations):

For each cella in otherrng
Range("A1").Select
Selection.AutoFilter Field:=2, Criteria1:=cella
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0).Resize(txtteljes.Rows.Count -
1, txtteljes.Columns.Count)
Set txtszurt = txtteljes.SpecialCells(xlVisible)
If Not txtszurt Is Nothing Then
Selection.Delete Shift:=xlUp
End If
Selection.AutoFilter
Next

My problem is that when range txtszurt is empty (I see on the screen that no
rows are selected), the
If Not txtszurt Is Nothing Then
condition is still met, and similarly to Jeff's case all rows are deleted.
What's wrong? I hope you come back to this old topic.

Regards,
Stefi


Norman Jones ezt *rta:

Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Copy after Autofilter with no rows found

maybe...
Option Explicit
Sub testme()

Dim CellA As Range
Dim otherRng As Range
Dim txtteljes As Range
Dim txtszurt As Range

Set otherRng = Worksheets("sheet2").Range("a1:a3")

For Each CellA In otherRng
Range("A1").AutoFilter Field:=2, Criteria1:=CellA
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0) _
.Resize(txtteljes.Rows.Count - 1, _
txtteljes.Columns.Count)
Set txtszurt = Nothing
On Error Resume Next
Set txtszurt = txtteljes.SpecialCells(xlVisible)
On Error GoTo 0
If txtszurt Is Nothing Then
'do nothing
Else
txtszurt.Delete shift:=xlUp
'or txtszurt.entirerow.delete
End If
ActiveSheet.ShowAllData
Next CellA

End Sub

Stefi wrote:

Hi Norman,
I have a very similar problem. I use the following piece of code (I don't
repeat here the declarations):

For each cella in otherrng
Range("A1").Select
Selection.AutoFilter Field:=2, Criteria1:=cella
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0).Resize(txtteljes.Rows.Count -
1, txtteljes.Columns.Count)
Set txtszurt = txtteljes.SpecialCells(xlVisible)
If Not txtszurt Is Nothing Then
Selection.Delete Shift:=xlUp
End If
Selection.AutoFilter
Next

My problem is that when range txtszurt is empty (I see on the screen that no
rows are selected), the
If Not txtszurt Is Nothing Then
condition is still met, and similarly to Jeff's case all rows are deleted.
What's wrong? I hope you come back to this old topic.

Regards,
Stefi

Norman Jones ezt *rta:

Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B





--

Dave Peterson
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,646
Default Copy after Autofilter with no rows found

Thanks Dave, line
Set txtszurt = Nothing
was the key!

Regards,
Stefi


Dave Peterson ezt *rta:

maybe...
Option Explicit
Sub testme()

Dim CellA As Range
Dim otherRng As Range
Dim txtteljes As Range
Dim txtszurt As Range

Set otherRng = Worksheets("sheet2").Range("a1:a3")

For Each CellA In otherRng
Range("A1").AutoFilter Field:=2, Criteria1:=CellA
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0) _
.Resize(txtteljes.Rows.Count - 1, _
txtteljes.Columns.Count)
Set txtszurt = Nothing
On Error Resume Next
Set txtszurt = txtteljes.SpecialCells(xlVisible)
On Error GoTo 0
If txtszurt Is Nothing Then
'do nothing
Else
txtszurt.Delete shift:=xlUp
'or txtszurt.entirerow.delete
End If
ActiveSheet.ShowAllData
Next CellA

End Sub

Stefi wrote:

Hi Norman,
I have a very similar problem. I use the following piece of code (I don't
repeat here the declarations):

For each cella in otherrng
Range("A1").Select
Selection.AutoFilter Field:=2, Criteria1:=cella
Set txtteljes = ActiveSheet.AutoFilter.Range.Rows
Set txtteljes = txtteljes.Offset(1, 0).Resize(txtteljes.Rows.Count -
1, txtteljes.Columns.Count)
Set txtszurt = txtteljes.SpecialCells(xlVisible)
If Not txtszurt Is Nothing Then
Selection.Delete Shift:=xlUp
End If
Selection.AutoFilter
Next

My problem is that when range txtszurt is empty (I see on the screen that no
rows are selected), the
If Not txtszurt Is Nothing Then
condition is still met, and similarly to Jeff's case all rows are deleted.
What's wrong? I hope you come back to this old topic.

Regards,
Stefi

âžNorman Jones❠ezt Ã*rta:

Hi Jeff,

Try something like:

Public Sub Tester02C()
Dim rng As Range
Dim rng1 As Range
Dim destRng As Range
Dim srcSh As Worksheet
Dim destSh As Worksheet

With ActiveWorkbook
Set srcSh = .Sheets("Index")
Set destSh = .Sheets("Call First")
Set destRng = destSh.Range("A10") '<<=== CHANGE
End With

srcSh.Cells.AutoFilter _
field:=2, _
Criteria1:="CF"

Set rng = srcSh.AutoFilter.Range
Set rng = rng.Offset(1).Resize(rng.Rows.Count - 1)

On Error Resume Next
Set rng1 = rng.SpecialCells(xlCellTypeVisible)
On Error GoTo 0

If Not rng1 Is Nothing Then
rng1.Copy Destination:=destRng
End If

srcSh.Cells.AutoFilter

End Sub

---
Regards,
Norman



"Jeff B" wrote in message
...
I've run into a quirky situation. I have a row of labels and then my data
below that. I'm using Autofilter to select rows below the labels meeting
certain criteria then copying them to another place. It works fine unless
I
have no rows meeting my criteria. Then I wind up copying the non-filtered
rows instead. Any help would be appreciated. (Range(strEmptyCell finds the
first empty row to copy to.) I'm using the code below:

Sheets(Index).Select
Sheets(Index).Range("a1").AutoFilter _
field:=3, Criteria1:="CF*"
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Copy

Sheets("Call First").Activate
Range(strEmptyCell).PasteSpecial (xlPasteValues)
Range("A1").Select
Sheets(Index).Activate

Set rngCopyRange = ActiveCell.CurrentRegion
rngCopyRange.Offset(1, 0).Resize(rngCopyRange.Rows.Count - 1, _
rngCopyRange.Columns.Count).Delete
Range("a1", "C1").AutoFilter 'Filter OFF
--
Jeff B




--

Dave Peterson

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
Excel copy only visible rows from autofilter duketter Excel Discussion (Misc queries) 2 June 30th 08 10:55 PM
In Excel, How do I get AutoFilter to provide# of records found? DougD Excel Discussion (Misc queries) 1 June 19th 08 07:51 PM
Copy Rows found using Find All feature Scott H Excel Discussion (Misc queries) 3 May 2nd 05 06:04 PM
how to display the count of lines found by autofilter? elaineb Excel Discussion (Misc queries) 1 April 6th 05 07:08 PM


All times are GMT +1. The time now is 03:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright 2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"