Defining 2 Dynamic Ranges on Same Worksheet

J.D

New Member
Joined
Feb 21, 2012
Messages
2
I have 2 ranges (each with headers and underlying text data) stacked on top of one another on the same worksheet. I am attempting to write a macro that autofilters the first range, copies and pastes data I need from each column to a separate worksheet, and then moves down to the second range (which is 2 blank rows below the end of range #1) to do the same thing. Filtering the first range is easy because it alway begins on row 11 but the 2nd is difficult for me because the first range always has a varying number of rows. here is a sample of the code I have that works for one of the columns in the top data range:

Code:
ActiveSheet.Range("b11", Range("k11").End(xlDown)).AutoFilter Field:=1, Criteria1:="<>Zz"
    Range("b11").End(xlDown).Offset(-2, 0).Select
    If ActiveCell.Value = "" Then GoTo Skip
    Range("b11", Range("b11").End(xlDown)).Copy
    Sheets(1).Select
    Range("b11").Select
    ActiveSheet.Paste
    Sheets(2).Select
    Skip:

basically I'd like to just define both of these ranges so it will be easier to put into a loop. can anybody help? I have searched extensively for an answer to this but have been unable to figure it out.

ps-long time reader but first time I have come to the board with a post. even if this goes unanswered this board is a great thing and thank you to all who post here
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
So, you're saying that the second range starts after 2 blank rows after the end of the first range?

So the start of the second range would be:
Code:
Range("b11").End(xlDown).Offset(3)
?

You could try
Code:
ActiveSheet.Range("b11").End(xlDown).Offset(3).CurrentRegion.AutoFilter etc etc
 
Upvote 0
thanks Glenn, that is correct. so to define the entire second range from columns B to K and down it would be something like:
Code:
Dim Range2 as range
 
activesheet.range("b11").end(xldown).offset(3).select
set range2 =  Range(Selection,range("k10000").end(xlup)).select
<!-- / message --><!-- sig -->

???

I will attempt to see if this works but sounds logical. thanks again.
 
Upvote 0

Forum statistics

Threads
1,215,432
Messages
6,124,859
Members
449,194
Latest member
HellScout

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top