PC Review


Reply
Thread Tools Rate Thread

Copying Range Based On Certain Criteria? Possible looping through the Range

 
 
Big H
Guest
Posts: n/a
 
      27th Oct 2006
Hi There,

the problem I have is this:

I have a dynamic range of data A2:H?

if ColumnA = Actual, ColumnH = CCLS, within the same row or rows, I want to
copy that information and paste it onto another sheet. Is there a way of
looping through the rows and copying to another sheet?

At present I have code (using the recorder) whereby I put a filter on the
columns and set the criteria I want, then I have defined a Name (A_CCLS),
which is dynamic, copy this range and paste it. The problem with this is
that sometimes ColumnH will not have CCLS within it and this causes an error
within the code.

regards Harry


 
Reply With Quote
 
 
 
 
Tom Ogilvy
Guest
Posts: n/a
 
      27th Oct 2006
If your code works well except for this one problem, then integrate a check
to see if you should copy or not. One way:
' apply your filter then
set rng = Activesheet.Autofilter.Range
s = rng.columns(1).Address
s1 = rng.Columns(8).Address
cnt = Evaluate("Sum(--(" & s & "=""Actual""),--(" & s1 & "=""CCLS""))")
if cnt > 1 then
' code to do the copying
end if


another

Dim rng as Range

' after you have applied the critieria to the data and before you attempt to
copy
set rng = ActiveSheet.Autofilter.Columns(1)
if rng.Specialcells(xlVisible).Count > 1 then
' do the copy

End if


If it is simpler, perhaps that if CCLS exists in column H, then you will
have rows to copy you could check with

if Application.Countif(Activesheet.Autofilter.Range.Columns(8),"CCLS") > 0
then


end if

--
Regards,
Tom Ogilvy



"Big H" <(E-Mail Removed)> wrote in message
news:%23rwuBlW%(E-Mail Removed)...
> Hi There,
>
> the problem I have is this:
>
> I have a dynamic range of data A2:H?
>
> if ColumnA = Actual, ColumnH = CCLS, within the same row or rows, I want
> to copy that information and paste it onto another sheet. Is there a way
> of looping through the rows and copying to another sheet?
>
> At present I have code (using the recorder) whereby I put a filter on the
> columns and set the criteria I want, then I have defined a Name (A_CCLS),
> which is dynamic, copy this range and paste it. The problem with this is
> that sometimes ColumnH will not have CCLS within it and this causes an
> error within the code.
>
> regards Harry
>



 
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
Summing a range of cells based on criteria in another range Jack Microsoft Excel Worksheet Functions 2 5th Nov 2009 01:46 AM
Copying a range based on criteria AmyTaylor Microsoft Excel Programming 1 11th Jul 2006 07:01 PM
Copying a range based on criteria AmyTaylor Microsoft Excel Programming 0 11th Jul 2006 04:47 PM
copying dynamic range based on cell outside of range xcelelder Microsoft Excel Programming 3 29th Sep 2005 05:08 PM
group rows in a range based on criteria from another range (vba) Andy Microsoft Excel Programming 2 28th Apr 2004 03:26 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:30 AM.