Reduce size of Range - Syntax question

parsellj

New Member
Joined
Jan 14, 2013
Messages
3
I hope this is a trivial question!
Given a Worksheet variable - WS,
and a Single Column Range on that Worksheet - V (eg G1:G260),
and an Index -- i where i is the index of the first row of interest in that range (eg 12),
What is the VB or VBA syntax for setting V to be the Range starting with G12 and ending at G260.

I am looking for the "proper" idomatic way to do this and am having a mental block.
TIA,
Jim
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Jim

There are different ways to do this, none of which I would say were the 'proper' way.

Here's one.
Code:
Set rng = Range("G1:G260")

idx = 12

Set rngNew = Rng.Offset(idx - 1).Resize(Rng.Rows.Count - idx + 1)

Msgbox rngNew.Address

Here's another one.
Code:
Set rng = Range("G1:G260")

idx = 12

Set rngNew = Range(rng.Cells(idx, 1), rng.Cells(rng.Rows.Count, 1))

MsgBox rngNew.Address
 
Upvote 0
Jim

There are different ways to do this, none of which I would say were the 'proper' way.

Here's one.
Code:
Set rng = Range("G1:G260")

idx = 12

Set rngNew = Rng.Offset(idx - 1).Resize(Rng.Rows.Count - idx + 1)

Msgbox rngNew.Address

Here's another one.
Code:
Set rng = Range("G1:G260")

idx = 12

Set rngNew = Range(rng.Cells(idx, 1), rng.Cells(rng.Rows.Count, 1))

MsgBox rngNew.Address
And here is another one...
Code:
Set rng = Range("G1:G260")

idx = 12

Set rngNew = Intersect(rng, rng.Offset(idx - 1))

MsgBox rngNew.Address
 
Upvote 0
Thanks for both of your answers. I was using a "slightly" mangled version of the 2nd approach - a mental block somehow had me using Cells rather than Range as the first term after the = sign - bad (overflow) result! This was a bit more awkward since the code actually lives in a VSTO solution.
Thanks for helping me over that one and for two other ways of getting the desired results! Actually I like both #1 and #3 better than #2!
 
Upvote 0

Forum statistics

Threads
1,214,923
Messages
6,122,286
Members
449,076
Latest member
kenyanscott

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