Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Combobox Rowsource

HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Combobox Rowsource

Check out the Help this topic. You will see :
"The RowSource property accepts worksheet ranges from Microsoft Excel."

NickHK

"kirke" wrote in message
oups.com...
HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default Combobox Rowsource

i've used something like this:

Dim cbRsource As String
Dim Lastrow As Long
Lastrow = Worksheets("emp").Range("C100").End(xlUp).Row
cbRsource = "'emp'!C2:C" & Lastrow ' which is the sheetname and the range in
column c

With Me.ListBox1
..Visible = True
..RowSource = cbRsource
End With


--


Gary


"kirke" wrote in message
oups.com...
HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Combobox Rowsource

I'm confused with access.
I think i cannot use SQL in excel.
Then does anybody know how to filter the rowsource for combobox?

I mean, if column B have the data : 1 1 2 2 3 3 4 4
Then, If i put rowsource="Sheet1!B:B" then combobox shows 1 1 2 2 3 3 4
4.
I wanna put only 1 2 3 4.
Plz help me.

Thx.



GKeramidas wrote:
i've used something like this:

Dim cbRsource As String
Dim Lastrow As Long
Lastrow = Worksheets("emp").Range("C100").End(xlUp).Row
cbRsource = "'emp'!C2:C" & Lastrow ' which is the sheetname and the range in
column c

With Me.ListBox1
.Visible = True
.RowSource = cbRsource
End With


--


Gary


"kirke" wrote in message
oups.com...
HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Combobox Rowsource

Then you will need to cut some code to create a new list of unique items,
and use that, or load unique items directly, like this

Dim i As Long
Dim cArray As Long
Dim ary

With ActiveSheet
ReDim ary(0 To 0)
cArray = 0
For i = 1 To .Cells(.Rows.Count, "B").End(xlUp).Row
If IsError(Application.Match(Cells(i, "B").Value, ary, 0)) Then
ReDim Preserve ary(0 To cArray)
ary(cArray) = .Cells(i, "B").Value
cArray = cArray + 1
End If
Next i
End With

Me.ComboBox1.List = ary




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"kirke" wrote in message
ups.com...
I'm confused with access.
I think i cannot use SQL in excel.
Then does anybody know how to filter the rowsource for combobox?

I mean, if column B have the data : 1 1 2 2 3 3 4 4
Then, If i put rowsource="Sheet1!B:B" then combobox shows 1 1 2 2 3 3 4
4.
I wanna put only 1 2 3 4.
Plz help me.

Thx.



GKeramidas wrote:
i've used something like this:

Dim cbRsource As String
Dim Lastrow As Long
Lastrow = Worksheets("emp").Range("C100").End(xlUp).Row
cbRsource = "'emp'!C2:C" & Lastrow ' which is the sheetname and the

range in
column c

With Me.ListBox1
.Visible = True
.RowSource = cbRsource
End With


--


Gary


"kirke" wrote in message
oups.com...
HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I

put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!






  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11
Default Combobox Rowsource

Wow. Thx Bob.
I really appreciate it!!!!!!!!!!


Bob Phillips wrote:
Then you will need to cut some code to create a new list of unique items,
and use that, or load unique items directly, like this

Dim i As Long
Dim cArray As Long
Dim ary

With ActiveSheet
ReDim ary(0 To 0)
cArray = 0
For i = 1 To .Cells(.Rows.Count, "B").End(xlUp).Row
If IsError(Application.Match(Cells(i, "B").Value, ary, 0)) Then
ReDim Preserve ary(0 To cArray)
ary(cArray) = .Cells(i, "B").Value
cArray = cArray + 1
End If
Next i
End With

Me.ComboBox1.List = ary




--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"kirke" wrote in message
ups.com...
I'm confused with access.
I think i cannot use SQL in excel.
Then does anybody know how to filter the rowsource for combobox?

I mean, if column B have the data : 1 1 2 2 3 3 4 4
Then, If i put rowsource="Sheet1!B:B" then combobox shows 1 1 2 2 3 3 4
4.
I wanna put only 1 2 3 4.
Plz help me.

Thx.



GKeramidas wrote:
i've used something like this:

Dim cbRsource As String
Dim Lastrow As Long
Lastrow = Worksheets("emp").Range("C100").End(xlUp).Row
cbRsource = "'emp'!C2:C" & Lastrow ' which is the sheetname and the

range in
column c

With Me.ListBox1
.Visible = True
.RowSource = cbRsource
End With


--


Gary


"kirke" wrote in message
oups.com...
HI all.
I write vba code for combo box.

formCombo.CmbDate.RowSource = "SELECT DISTINCT pp FROM SS ORDER BY
pp;"


but it doesn't work!
In here, pp is the column name and SS is sheet name. Is it wrong? I

put
this code in "UserForm_Initialize"
And there's error on "formCombo.Show"
Thank you!



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
RowSource for Sheet ComboBox Minitman Excel Worksheet Functions 3 March 24th 08 09:43 PM
Combobox rowsource Marinos Andreou Excel Programming 2 March 7th 06 05:08 PM
combobox rowsource as code JasonSelf[_20_] Excel Programming 1 September 13th 05 08:44 PM
How Do I Load A ComboBox RowSource From The Results Of Another ComboBox Minitman[_4_] Excel Programming 3 October 26th 04 07:58 PM
combobox rowsource Newbie Excel Programming 1 September 8th 04 12:21 PM


All times are GMT +1. The time now is 10:59 PM.

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"