PC Review


Reply
Thread Tools Rate Thread

Can anyone help, this problem has been bugging me for the last 6 hours

 
 
Mulberry
Guest
Posts: n/a
 
      13th Nov 2006
Hi there,

I am pretty new to vba and having extreme difficulty programming a loop
that uses SpecialCells(xlvisible)

the macro runs fine if there is something in the filter, the problem is
the data is dynamic and the filter can sometimes produce an empty range
and then the marco gives a run time error


Basically what I want to do is filter a list in place, copy the list
from the second row to the end of the data range for the selected
criteria (leaving off the header) and pasting this in another cell in
another sheet. But if this copied range is empty to skip the copy/paste
altogther.

I would appreciate any help here

 
Reply With Quote
 
 
 
 
=?Utf-8?B?Q2hhcmxlcyBDaGlja2VyaW5n?=
Guest
Posts: n/a
 
      13th Nov 2006
I'm not sure how much help I'll be as I don't have your code to look at, but
I'll give it a shot.
Range("YourRange").AutoFilter(...)
If Range("A" & Rows.Count).End(xlUp).Row = _
Range("YourRange").Cells(1).Row Then
'No Filtered Items Move On
Else
Range("YourRange").SpecialCells(xlCellTypeVisible).Copy
End If
--
Charles Chickering

"A good example is twice the value of good advice."


"Mulberry" wrote:

> Hi there,
>
> I am pretty new to vba and having extreme difficulty programming a loop
> that uses SpecialCells(xlvisible)
>
> the macro runs fine if there is something in the filter, the problem is
> the data is dynamic and the filter can sometimes produce an empty range
> and then the marco gives a run time error
>
>
> Basically what I want to do is filter a list in place, copy the list
> from the second row to the end of the data range for the selected
> criteria (leaving off the header) and pasting this in another cell in
> another sheet. But if this copied range is empty to skip the copy/paste
> altogther.
>
> I would appreciate any help here
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Nov 2006
Another one:

with .autofilter.range
if .columns(1).cells.specialcells(xlcelltypevisible).cells.count = 1 then
'only headers
else
'do what you want
end if
end with



Mulberry wrote:
>
> Hi there,
>
> I am pretty new to vba and having extreme difficulty programming a loop
> that uses SpecialCells(xlvisible)
>
> the macro runs fine if there is something in the filter, the problem is
> the data is dynamic and the filter can sometimes produce an empty range
> and then the marco gives a run time error
>
> Basically what I want to do is filter a list in place, copy the list
> from the second row to the end of the data range for the selected
> criteria (leaving off the header) and pasting this in another cell in
> another sheet. But if this copied range is empty to skip the copy/paste
> altogther.
>
> I would appreciate any help here


--

Dave Peterson
 
Reply With Quote
 
Dana DeLouis
Guest
Posts: n/a
 
      13th Nov 2006
Just another idea that doesn't use SpecialCells:

Sub Demo()
Dim NumRecords As Long

With ActiveSheet.AutoFilter.Range
NumRecords = WorksheetFunction.Subtotal(2, .Columns(1))

If NumRecords >= 1 Then
'Offset by 1...No headers.
.Offset(1).Copy Worksheets(2).Range("A1")
End If
End With
End Sub

--
HTH :>)
Dana DeLouis
Windows XP & Office 2003


"Dave Peterson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Another one:
>
> with .autofilter.range
> if .columns(1).cells.specialcells(xlcelltypevisible).cells.count = 1 then
> 'only headers
> else
> 'do what you want
> end if
> end with
>
>
>
> Mulberry wrote:
>>
>> Hi there,
>>
>> I am pretty new to vba and having extreme difficulty programming a loop
>> that uses SpecialCells(xlvisible)
>>
>> the macro runs fine if there is something in the filter, the problem is
>> the data is dynamic and the filter can sometimes produce an empty range
>> and then the marco gives a run time error
>>
>> Basically what I want to do is filter a list in place, copy the list
>> from the second row to the end of the data range for the selected
>> criteria (leaving off the header) and pasting this in another cell in
>> another sheet. But if this copied range is empty to skip the copy/paste
>> altogther.
>>
>> I would appreciate any help here

>
> --
>
> Dave Peterson



 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Nov 2006
Please don't filter to show empty cells <vbg>.

Dana DeLouis wrote:
>
> Just another idea that doesn't use SpecialCells:
>
> Sub Demo()
> Dim NumRecords As Long
>
> With ActiveSheet.AutoFilter.Range
> NumRecords = WorksheetFunction.Subtotal(2, .Columns(1))
>
> If NumRecords >= 1 Then
> 'Offset by 1...No headers.
> .Offset(1).Copy Worksheets(2).Range("A1")
> End If
> End With
> End Sub
>
> --
> HTH :>)
> Dana DeLouis
> Windows XP & Office 2003
>
> "Dave Peterson" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > Another one:
> >
> > with .autofilter.range
> > if .columns(1).cells.specialcells(xlcelltypevisible).cells.count = 1 then
> > 'only headers
> > else
> > 'do what you want
> > end if
> > end with
> >
> >
> >
> > Mulberry wrote:
> >>
> >> Hi there,
> >>
> >> I am pretty new to vba and having extreme difficulty programming a loop
> >> that uses SpecialCells(xlvisible)
> >>
> >> the macro runs fine if there is something in the filter, the problem is
> >> the data is dynamic and the filter can sometimes produce an empty range
> >> and then the marco gives a run time error
> >>
> >> Basically what I want to do is filter a list in place, copy the list
> >> from the second row to the end of the data range for the selected
> >> criteria (leaving off the header) and pasting this in another cell in
> >> another sheet. But if this copied range is empty to skip the copy/paste
> >> altogther.
> >>
> >> I would appreciate any help here

> >
> > --
> >
> > Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      13th Nov 2006
I have a similar situation and use this test. In some available cell place
this formula for a column that is exclusively numbers:
=subtotal(9,F2:F2000)
If no data shows with the autofilter, the formula will return "0".

In your code:

sub test()
For each suchand such in sheets

Code
Autofilter
If Range("Z1") = 0 then
goto continue
end if
Do copying etc.
Continue:
Next

end sub
--
Best wishes,

Jim


"Mulberry" wrote:

> Hi there,
>
> I am pretty new to vba and having extreme difficulty programming a loop
> that uses SpecialCells(xlvisible)
>
> the macro runs fine if there is something in the filter, the problem is
> the data is dynamic and the filter can sometimes produce an empty range
> and then the marco gives a run time error
>
>
> Basically what I want to do is filter a list in place, copy the list
> from the second row to the end of the data range for the selected
> criteria (leaving off the header) and pasting this in another cell in
> another sheet. But if this copied range is empty to skip the copy/paste
> altogther.
>
> I would appreciate any help here
>
>

 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Nov 2006
I meant that if the first column of that autofilter range has nothing but empty
cells, then =subtotal(2,xx) will return 0.

If there are no numbers in that visible range, then =subtotal(2,xx) will also
return 0.

=subtotal(3,xx)
will do a counta--but has the same trouble if all the visible cells are empty.

Dave Peterson wrote:
>
> Please don't filter to show empty cells <vbg>.
>
> Dana DeLouis wrote:
> >
> > Just another idea that doesn't use SpecialCells:
> >
> > Sub Demo()
> > Dim NumRecords As Long
> >
> > With ActiveSheet.AutoFilter.Range
> > NumRecords = WorksheetFunction.Subtotal(2, .Columns(1))
> >
> > If NumRecords >= 1 Then
> > 'Offset by 1...No headers.
> > .Offset(1).Copy Worksheets(2).Range("A1")
> > End If
> > End With
> > End Sub
> >
> > --
> > HTH :>)
> > Dana DeLouis
> > Windows XP & Office 2003
> >
> > "Dave Peterson" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Another one:
> > >
> > > with .autofilter.range
> > > if .columns(1).cells.specialcells(xlcelltypevisible).cells.count = 1 then
> > > 'only headers
> > > else
> > > 'do what you want
> > > end if
> > > end with
> > >
> > >
> > >
> > > Mulberry wrote:
> > >>
> > >> Hi there,
> > >>
> > >> I am pretty new to vba and having extreme difficulty programming a loop
> > >> that uses SpecialCells(xlvisible)
> > >>
> > >> the macro runs fine if there is something in the filter, the problem is
> > >> the data is dynamic and the filter can sometimes produce an empty range
> > >> and then the marco gives a run time error
> > >>
> > >> Basically what I want to do is filter a list in place, copy the list
> > >> from the second row to the end of the data range for the selected
> > >> criteria (leaving off the header) and pasting this in another cell in
> > >> another sheet. But if this copied range is empty to skip the copy/paste
> > >> altogther.
> > >>
> > >> I would appreciate any help here
> > >
> > > --
> > >
> > > Dave Peterson

>
> --
>
> Dave Peterson


--

Dave Peterson
 
Reply With Quote
 
Dave Peterson
Guest
Posts: n/a
 
      13th Nov 2006
But if all the visible cells in that range are text, then won't you get 0, too?

And if you're really unlucky, the numbers could sum to 0 (-1+1-3+2+1...)



Jim Jackson wrote:
>
> I have a similar situation and use this test. In some available cell place
> this formula for a column that is exclusively numbers:
> =subtotal(9,F2:F2000)
> If no data shows with the autofilter, the formula will return "0".
>
> In your code:
>
> sub test()
> For each suchand such in sheets
>
> Code
> Autofilter
> If Range("Z1") = 0 then
> goto continue
> end if
> Do copying etc.
> Continue:
> Next
>
> end sub
> --
> Best wishes,
>
> Jim
>
> "Mulberry" wrote:
>
> > Hi there,
> >
> > I am pretty new to vba and having extreme difficulty programming a loop
> > that uses SpecialCells(xlvisible)
> >
> > the macro runs fine if there is something in the filter, the problem is
> > the data is dynamic and the filter can sometimes produce an empty range
> > and then the marco gives a run time error
> >
> >
> > Basically what I want to do is filter a list in place, copy the list
> > from the second row to the end of the data range for the selected
> > criteria (leaving off the header) and pasting this in another cell in
> > another sheet. But if this copied range is empty to skip the copy/paste
> > altogther.
> >
> > I would appreciate any help here
> >
> >


--

Dave Peterson
 
Reply With Quote
 
=?Utf-8?B?SmltIEphY2tzb24=?=
Guest
Posts: n/a
 
      14th Nov 2006
This is a possibility I had not thought about. In my case the numbers are
always positive and the data in that particular column is always numerical.
Now you.ve gone and got technical on me.
--
Best wishes,

Jim


"Dave Peterson" wrote:

> But if all the visible cells in that range are text, then won't you get 0, too?
>
> And if you're really unlucky, the numbers could sum to 0 (-1+1-3+2+1...)
>
>
>
> Jim Jackson wrote:
> >
> > I have a similar situation and use this test. In some available cell place
> > this formula for a column that is exclusively numbers:
> > =subtotal(9,F2:F2000)
> > If no data shows with the autofilter, the formula will return "0".
> >
> > In your code:
> >
> > sub test()
> > For each suchand such in sheets
> >
> > Code
> > Autofilter
> > If Range("Z1") = 0 then
> > goto continue
> > end if
> > Do copying etc.
> > Continue:
> > Next
> >
> > end sub
> > --
> > Best wishes,
> >
> > Jim
> >
> > "Mulberry" wrote:
> >
> > > Hi there,
> > >
> > > I am pretty new to vba and having extreme difficulty programming a loop
> > > that uses SpecialCells(xlvisible)
> > >
> > > the macro runs fine if there is something in the filter, the problem is
> > > the data is dynamic and the filter can sometimes produce an empty range
> > > and then the marco gives a run time error
> > >
> > >
> > > Basically what I want to do is filter a list in place, copy the list
> > > from the second row to the end of the data range for the selected
> > > criteria (leaving off the header) and pasting this in another cell in
> > > another sheet. But if this copied range is empty to skip the copy/paste
> > > altogther.
> > >
> > > I would appreciate any help here
> > >
> > >

>
> --
>
> Dave Peterson
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hours Weekly To Hours Monthly Problem =?Utf-8?B?UmF5IFMu?= Microsoft Access 8 9th Oct 2007 02:14 PM
Problem converting Hours to Days, Hours, Minutes =?Utf-8?B?Wnl6eng=?= Microsoft Excel Worksheet Functions 4 24th Oct 2005 04:19 PM
This is really bugging me now! =?Utf-8?B?U3RldmU=?= Microsoft Excel New Users 4 29th Jul 2005 05:08 PM
Is this a known bug, or is it just me bugging? Michael Wong Microsoft Access Form Coding 4 2nd Apr 2004 09:21 AM
Is RPC Bugging You? hlpr Windows XP Performance 0 12th Aug 2003 02:27 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:24 PM.