Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Copying Range Based On Certain Criteria? Possible looping through the Range

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


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Copying Range Based On Certain Criteria? Possible looping through the Range

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.C olumns(8),"CCLS") 0
then


end if

--
Regards,
Tom Ogilvy



"Big H" wrote in message
...
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
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
Summing a range of cells based on criteria in another range Jack Excel Worksheet Functions 2 November 5th 09 01:46 AM
Copying a range based on criteria AmyTaylor[_66_] Excel Programming 1 July 11th 06 07:01 PM
Copying a range based on criteria AmyTaylor[_65_] Excel Programming 0 July 11th 06 04:47 PM
copying dynamic range based on cell outside of range xcelelder Excel Programming 3 September 29th 05 05:08 PM
group rows in a range based on criteria from another range (vba) Andy Excel Programming 2 April 28th 04 03:26 AM


All times are GMT +1. The time now is 09:16 PM.

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

About Us

"It's about Microsoft Excel"