Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Populate a Multicolumn ComboBox with filtered range

I have a worksheet with 40 columns.

This is part of the worksheet:

-- A
B C
D .... BA
1 ID
BussinessType Name
City 1
2 123451
1 John Lennon New Orleans
3 123452
2 Luigi Federline Ontario
4 123453
1 Arthur Diaz Los Angeles
5 123454
2 Jane Lisboa Portland

I want to populate a 4-column combobox (within these columns) with
rows where BussinessType is equal to 1.


This is my Code:

'----Start Code----

Sub Populate_Combobox()

Dim rnData As Range
Dim vaData As Variant
Dim i As Long

With Sheet1

Set rnData = .Range(.Range("B1"), .Range("B65536").End(xlUp))

rnData.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("BA1"), Unique:=True

vaData = .Range(.Range("BA2"), .Range("BA65536").End(xlUp)).Value

.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents

End With

With ComboBox1
.Clear
.List = vaData
.ListIndex = -1
End With

End Sub

'----End Code----


But this only works in a single column combobox, and still gives me
all the records.

What is the problem?

Juan

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Populate a Multicolumn ComboBox with filtered range

You need to have a criteria range that specifies to copy records with
Business Type 1.

To do the 4 columns

Sub Populate_Combobox()

Dim rnData As Range
Dim vaData As Variant
Dim i As Long
Dim CritRng as Range

With Sheet1
' Set up the criteria range
Set crtRng = .Range("F1:F2")
.Range("F1").Value = .Range("B2").Value
.Range("F2").Value = 1
Set rnData = .Range(.Range("A1"), .Range("A65536").End(xlUp)).Resize(,4)
' Put headers in row1
.Range("BA1").Resize(1,4).Value = .Range("A1").Resize(1,4).value
rnData.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=crtRng, _
CopyToRange:=.Range("BA1").Resize(1,4), _
Unique:=False

vaData = .Range(.Range("BA2"),
..Range("BA65536").End(xlUp)).Resize(,4).Value

.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents

End With

With ComboBox1
.Clear
.ColumnCount = 4
.List = vaData
.ListIndex = -1
End With
' clear out the criteria range
crtRng.clearcontents
End Sub


--
Regards,
Tom Ogilvy


" wrote:

I have a worksheet with 40 columns.

This is part of the worksheet:

-- A
B C
D .... BA
1 ID
BussinessType Name
City 1
2 123451
1 John Lennon New Orleans
3 123452
2 Luigi Federline Ontario
4 123453
1 Arthur Diaz Los Angeles
5 123454
2 Jane Lisboa Portland

I want to populate a 4-column combobox (within these columns) with
rows where BussinessType is equal to 1.


This is my Code:

'----Start Code----

Sub Populate_Combobox()

Dim rnData As Range
Dim vaData As Variant
Dim i As Long

With Sheet1

Set rnData = .Range(.Range("B1"), .Range("B65536").End(xlUp))

rnData.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("BA1"), Unique:=True

vaData = .Range(.Range("BA2"), .Range("BA65536").End(xlUp)).Value

.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents

End With

With ComboBox1
.Clear
.List = vaData
.ListIndex = -1
End With

End Sub

'----End Code----


But this only works in a single column combobox, and still gives me
all the records.

What is the problem?

Juan


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6
Default Populate a Multicolumn ComboBox with filtered range

On Feb 14, 3:20 pm, Tom Ogilvy
wrote:
You need to have a criteria range that specifies to copy records with
Business Type 1.

To do the 4 columns

Sub Populate_Combobox()

Dim rnData As Range
Dim vaData As Variant
Dim i As Long
Dim CritRng as Range

With Sheet1
' Set up the criteria range
Set crtRng = .Range("F1:F2")
.Range("F1").Value = .Range("B2").Value
.Range("F2").Value = 1
Set rnData = .Range(.Range("A1"), .Range("A65536").End(xlUp)).Resize(,4)
' Put headers in row1
.Range("BA1").Resize(1,4).Value = .Range("A1").Resize(1,4).value
rnData.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=crtRng, _
CopyToRange:=.Range("BA1").Resize(1,4), _
Unique:=False

vaData = .Range(.Range("BA2"),
.Range("BA65536").End(xlUp)).Resize(,4).Value

.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents

End With

With ComboBox1
.Clear
.ColumnCount = 4
.List = vaData
.ListIndex = -1
End With
' clear out the criteria range
crtRng.clearcontents
End Sub

--
Regards,
Tom Ogilvy



" wrote:
I have a worksheet with 40 columns.


This is part of the worksheet:


-- A
B C
D .... BA
1 ID
BussinessType Name
City 1
2 123451
1 John Lennon New Orleans
3 123452
2 Luigi Federline Ontario
4 123453
1 Arthur Diaz Los Angeles
5 123454
2 Jane Lisboa Portland


I want to populate a 4-column combobox (within these columns) with
rows where BussinessType is equal to 1.


This is my Code:


'----Start Code----


Sub Populate_Combobox()


Dim rnData As Range
Dim vaData As Variant
Dim i As Long


With Sheet1


Set rnData = .Range(.Range("B1"), .Range("B65536").End(xlUp))


rnData.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("BA1"), Unique:=True


vaData = .Range(.Range("BA2"), .Range("BA65536").End(xlUp)).Value


.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents


End With


With ComboBox1
.Clear
.List = vaData
.ListIndex = -1
End With


End Sub


'----End Code----


But this only works in a single column combobox, and still gives me
all the records.


What is the problem?


Juan- Hide quoted text -


- Show quoted text -


I found the error. On the criteria range, the first value is of one of
the headers.

Set crtRng = .Range("F1:F2")
.Range("F1").Value = .Range("B1").Value ' It was pointing to the
first value instead of the header

Juan

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Populate a Multicolumn ComboBox with filtered range

How can B1 be the 1st value instead of the header?

--
Regards,
Tom Ogilvy

wrote in message
oups.com...
On Feb 14, 3:20 pm, Tom Ogilvy
wrote:
You need to have a criteria range that specifies to copy records with
Business Type 1.

To do the 4 columns

Sub Populate_Combobox()

Dim rnData As Range
Dim vaData As Variant
Dim i As Long
Dim CritRng as Range

With Sheet1
' Set up the criteria range
Set crtRng = .Range("F1:F2")
.Range("F1").Value = .Range("B2").Value
.Range("F2").Value = 1
Set rnData = .Range(.Range("A1"),
.Range("A65536").End(xlUp)).Resize(,4)
' Put headers in row1
.Range("BA1").Resize(1,4).Value = .Range("A1").Resize(1,4).value
rnData.AdvancedFilter Action:=xlFilterCopy, _
CriteriaRange:=crtRng, _
CopyToRange:=.Range("BA1").Resize(1,4), _
Unique:=False

vaData = .Range(.Range("BA2"),
.Range("BA65536").End(xlUp)).Resize(,4).Value

.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents

End With

With ComboBox1
.Clear
.ColumnCount = 4
.List = vaData
.ListIndex = -1
End With
' clear out the criteria range
crtRng.clearcontents
End Sub

--
Regards,
Tom Ogilvy



" wrote:
I have a worksheet with 40 columns.


This is part of the worksheet:


-- A
B C
D .... BA
1 ID
BussinessType Name
City 1
2 123451
1 John Lennon New Orleans
3 123452
2 Luigi Federline Ontario
4 123453
1 Arthur Diaz Los Angeles
5 123454
2 Jane Lisboa Portland


I want to populate a 4-column combobox (within these columns) with
rows where BussinessType is equal to 1.


This is my Code:


'----Start Code----


Sub Populate_Combobox()


Dim rnData As Range
Dim vaData As Variant
Dim i As Long


With Sheet1


Set rnData = .Range(.Range("B1"), .Range("B65536").End(xlUp))


rnData.AdvancedFilter Action:=xlFilterCopy,
CopyToRange:=Range("BA1"), Unique:=True


vaData = .Range(.Range("BA2"), .Range("BA65536").End(xlUp)).Value


.Range(.Range("BA1"), .Range("BA65536").End(xlUp)).ClearContents


End With


With ComboBox1
.Clear
.List = vaData
.ListIndex = -1
End With


End Sub


'----End Code----


But this only works in a single column combobox, and still gives me
all the records.


What is the problem?


Juan- Hide quoted text -


- Show quoted text -


I found the error. On the criteria range, the first value is of one of
the headers.

Set crtRng = .Range("F1:F2")
.Range("F1").Value = .Range("B1").Value ' It was pointing to the
first value instead of the header

Juan



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
Multicolumn combobox Gromit Excel Programming 2 January 23rd 06 04:14 PM
MultiColumn ComboBox Paul Smith[_3_] Excel Programming 2 August 3rd 05 06:36 AM
Populate a Combobox from range. ex1302[_8_] Excel Programming 14 July 22nd 05 05:32 PM
MultiColumn ComboBox Value set/display Jim Zeeb[_2_] Excel Programming 5 June 13th 05 09:20 AM
populate multicolumn listbox? Alen32 Excel Programming 4 March 22nd 05 09:22 PM


All times are GMT +1. The time now is 02:04 AM.

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

About Us

"It's about Microsoft Excel"