"Building" Ranges from Smaller Ranges

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
Is it possible to "build" a range?
I have a column of cells with values in them (H9:H42).
I set ranges using a series of contingent cells in that range. These set ranges become the source of my named ranges which I use as data validation list sources.

Code:
Dim rng_biscuits as range
Dim rng_flowers as range
Dim combined as range

Set rng_biscuits = worksheets(sheet1).range("H9:H12")
Set rng_flowers = worksheets(sheet1).range("H30:H42")

Both rng_biscuits and rng_flowers may become the source range for a named range used in a list data validation.

Suppose I want my data validation list to be a combination of both ranges H9:H12 and H30:H42?

I tried
Code:
set combined = worksheets(sheet1).range("H9:H12,H30:H42")
\
But the list included all the values between H9:H42 in my data validation list. (I do not need values from H13:H29).
 

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
How about by using the union method

VBA Code:
Sub ark68()
    Dim rng_biscuits As Range
    Dim rng_flowers As Range
    Dim combined As Range
    
    Set rng_biscuits = Worksheets("Sheet1").Range("H9:H12")
    Set rng_flowers = Worksheets("Sheet1").Range("H30:H42")
    Set combined = Union(rng_biscuits, rng_flowers)
    
    combined.Value = "Hello"
End Sub
 
Upvote 0
That was too easy! (Except maybe for someone that was totally oblivious to that function!! :rolleyes:)
Thanks so much FryGirl!
 
Upvote 0
You are welcome. Glad it helped you, and trust me, I've received help many a time from the fine people on this site. :)
 
Upvote 0

Forum statistics

Threads
1,214,624
Messages
6,120,591
Members
448,973
Latest member
ksonnia

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