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

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)

Norie

Well-known Member
Joined
Apr 28, 2004
Messages
76,299
Office Version
  1. 365
Platform
  1. Windows
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
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,054
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
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
 

parsellj

New Member
Joined
Jan 14, 2013
Messages
3
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!
 

Watch MrExcel Video

Forum statistics

Threads
1,133,463
Messages
5,658,912
Members
418,476
Latest member
Tristram_ZX81

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
Top