Combobox add to list - two ranges

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
938
I am using this code:

VBA Code:
Dim lastrow As Integer
Dim lastrow2 As Integer
Dim adrow As Integer
Dim rng1 As Range
Dim rng2 As Range
Dim rng3 As Range

adrow = x_admin.Range("range_admin_header").Row + 1
lastrow = Application.WorksheetFunction.CountIf(x_admin.Range("J" & adrow & ":" & "J245"), "1") - 1
lastrow2 = Application.WorksheetFunction.CountIf(x_admin.Range("L" & adrow & ":" & "L245"), "1") - 1

Set rng1 = x_admin.Range("I" & adrow & ":" & "I" & adrow + lastrow)
Set rng2 = x_admin.Range("K" & adrow & ":" & "K" & adrow + lastrow2)
Set rng3 = Union(rng1, rng2)

query_combo.List = rng3.Value2

query_combo is a VBA combobox. But for some weird reason the combobox only lists rng1 values instead of the Union values with rng2.
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

diddi

Well-known Member
Joined
May 20, 2004
Messages
3,297
Office Version
  1. 2010
Platform
  1. Windows
query_combo.List = rng3.Value2 delete that "2"
 

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
938
Hi, this suggestion doesn't solve the problem. The value2 is just an option to avoid lookup of formatting.
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
query_combo.List = Application.Index(rng1.Resize(, 3).Value2, Evaluate("row(1:" & rng1.Rows.Count & ")"), Array(1, 3))
 

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
938

ADVERTISEMENT

Hi @Fluff this code works only for rng1. I am looking for the query_combo to concatenate rng1 and rng2 range values. I am still confused as to why the 'Union' in my code doesn't work as expected
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
Is your combo set to show 2 columns?
 

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
938

ADVERTISEMENT

No only one column
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,536
Office Version
  1. 365
Platform
  1. Windows
Then you will need to change the property if you want to show 2 columns
 

neodjandre

Well-known Member
Joined
Nov 29, 2006
Messages
938
But I only want to have 1 column with the values of rng2 being appended below the values of rng1. Perhaps I misunderstood the functionality of Union ?
 

Watch MrExcel Video

Forum statistics

Threads
1,129,500
Messages
5,636,690
Members
416,935
Latest member
Atulcp

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