Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Populate Combo-box from Multiple Sheets

I have a userform with combo-boxes and I'm trying to populate them from
information on multiple worksheets. The code I currently have to fill them
from one sheet is as follows ("Gain" is just to specify which box, since
there are many):

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain

' The items are in O2:O10000
Set GainCells = Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain

' Resume normal error handling
On Error GoTo 0

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain

How do I adjust this to add a range from another sheet?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Populate Combo-box from Multiple Sheets

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain
Dim sh as Worksheet

' The items are in O2:O10000
for each sh in worksheets(Array("Sheet2","Sheet5","Sheet7"))
Set GainCells = sh.Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain
' Resume normal error handling
On Error GoTo 0

Next sh

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain


--
Regards,
Tom Ogilvy

"MAWII" wrote:

I have a userform with combo-boxes and I'm trying to populate them from
information on multiple worksheets. The code I currently have to fill them
from one sheet is as follows ("Gain" is just to specify which box, since
there are many):

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain

' The items are in O2:O10000
Set GainCells = Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain

' Resume normal error handling
On Error GoTo 0

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain

How do I adjust this to add a range from another sheet?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 18
Default Populate Combo-box from Multiple Sheets

Thanks, Tom.

Is it possible to do it for different ranges? For example, the information
in the first sheet may be in column O, while the same information in the
second sheet may be in column J. I'd prefer not to have to reorganize the
worksheets if possible, but will if I have to.

Thanks!

"Tom Ogilvy" wrote:

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain
Dim sh as Worksheet

' The items are in O2:O10000
for each sh in worksheets(Array("Sheet2","Sheet5","Sheet7"))
Set GainCells = sh.Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain
' Resume normal error handling
On Error GoTo 0

Next sh

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain


--
Regards,
Tom Ogilvy

"MAWII" wrote:

I have a userform with combo-boxes and I'm trying to populate them from
information on multiple worksheets. The code I currently have to fill them
from one sheet is as follows ("Gain" is just to specify which box, since
there are many):

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain

' The items are in O2:O10000
Set GainCells = Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain

' Resume normal error handling
On Error GoTo 0

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain

How do I adjust this to add a range from another sheet?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Populate Combo-box from Multiple Sheets

Certainly. You would have to tell it by sheet what range to look in. Just
use another array to correspond to sheet name.

--
Regards,
Tom Ogilvy


"MAWII" wrote:

Thanks, Tom.

Is it possible to do it for different ranges? For example, the information
in the first sheet may be in column O, while the same information in the
second sheet may be in column J. I'd prefer not to have to reorganize the
worksheets if possible, but will if I have to.

Thanks!

"Tom Ogilvy" wrote:

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain
Dim sh as Worksheet

' The items are in O2:O10000
for each sh in worksheets(Array("Sheet2","Sheet5","Sheet7"))
Set GainCells = sh.Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain
' Resume normal error handling
On Error GoTo 0

Next sh

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain


--
Regards,
Tom Ogilvy

"MAWII" wrote:

I have a userform with combo-boxes and I'm trying to populate them from
information on multiple worksheets. The code I currently have to fill them
from one sheet is as follows ("Gain" is just to specify which box, since
there are many):

Dim GainCells As Range, CellGain As Range
Dim NoDupesGain As New Collection
Dim iGain As Integer, jGain As Integer
Dim Swap1Gain, Swap2Gain, ItemGain

' The items are in O2:O10000
Set GainCells = Range("O2:O10000")

' The next statement ignores the error caused
' by attempting to add a duplicate key to the collection.
' The duplicate is not added - which is just what we want!
On Error Resume Next
For Each CellGain In GainCells
NoDupesGain.Add CellGain.Value, CStr(CellGain.Value)
' Note: the 2nd argument (key) for the Add method must be a string
Next CellGain

' Resume normal error handling
On Error GoTo 0

' Sort the collection (optional)
For iGain = 1 To NoDupesGain.Count - 1
For jGain = iGain + 1 To NoDupesGain.Count
If NoDupesGain(iGain) NoDupesGain(jGain) Then
Swap1Gain = NoDupesGain(iGain)
Swap2Gain = NoDupesGain(jGain)
NoDupesGain.Add Swap1Gain, befo=jGain
NoDupesGain.Add Swap2Gain, befo=iGain
NoDupesGain.Remove iGain + 1
NoDupesGain.Remove jGain + 1
End If
Next jGain
Next iGain

' Add the sorted, non-duplicated items to a ListBox
For Each ItemGain In NoDupesGain
Antenna_Gain.AddItem ItemGain
Next ItemGain

How do I adjust this to add a range from another sheet?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help on VBA Code to populate multiple sheets [email protected] Excel Discussion (Misc queries) 1 January 15th 08 04:40 AM
Populate one combo box based on the selection of another combo box Alex Excel Programming 8 April 19th 07 06:40 PM
populate combo box enyaw Excel Discussion (Misc queries) 1 October 26th 06 03:13 PM
combo box multiple workbooks / sheets [email protected] Excel Programming 3 November 6th 05 09:56 PM
How am i able to populate a sumation for multiple sheets swiftcode Excel Worksheet Functions 2 September 29th 05 02:33 AM


All times are GMT +1. The time now is 11:22 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"