|
-
Feb 13th, 2006, 08:06 PM
#1
Thread Starter
Hyperactive Member
Combobox in a worksheet
Hi to all!
I've been searching on this forum topic for what I want to create for almost an hour now. All I found is using a combox with a userform, what I want is to create/include a combox into a worksheet. It's like when you have a list created from "Data->List->Create List.." menu. This combox will contain data coming from sql server.
Thanks in advance!
Last edited by dRAMmer; Mar 1st, 2006 at 08:01 PM.
live, code and die...
-
Feb 13th, 2006, 08:23 PM
#2
Re: Combobox in a worksheet
Wehn ever you need to know how to do something in VBA, just record a macro doing your needed task and then view the Module code generated. Although, I dont really recommend using the ActiveCell object but you get the idea. 
VB Code:
Sub Macro1()
'
' Macro1 Macro
' Macro recorded 2/13/2006 by VB/Office Guru
ActiveSheet.ListObjects.Add(xlSrcRange, Range("$A$1"), , xlNo).Name = "List1"
Range("A2").Select
ActiveCell.FormulaR1C1 = "test"
Range("A3").Select
ActiveCell.FormulaR1C1 = "red"
Range("A4").Select
ActiveCell.FormulaR1C1 = "blue"
Range("A5").Select
ActiveCell.FormulaR1C1 = "ttt"
Range("A6").Select
ActiveCell.FormulaR1C1 = "aaa"
Range("A1:A6").Sort Key1:=Range("A1"), Order1:=xlAscending, Header:= _
xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 13th, 2006, 08:33 PM
#3
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
Hi Rob!
Thanks for the quick reply. I have done already trying to see if I can make something out of it. But my problem remains that I can't create a "dynamic" combox out of it. If try to create it into a list then the connection will be lost. Here is what I'm trying to do:
- Create a combo box on a sheet
- Populate it with data from a select statement
- Have another combobox whose values depends or is filtered out by the value given by the first combobox. values will also be coming from database.
Can you give an example about this.
-
Feb 13th, 2006, 08:34 PM
#4
Re: Combobox in a worksheet
i think so. Does the combo's need to be like the filtering or sorting ones or can it be an ActiveX combo box?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 13th, 2006, 08:48 PM
#5
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
As much as possible I'd like to shy off from activeX, you see I have something similar done w/Smart Doc. But as you know, smart docs are hard to deploy. So I want a simple one, where users can just open the workbook and start typing.
The control is more of a filtering type.
-
Feb 15th, 2006, 07:12 PM
#6
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
Anybody there who can help? I would really appreciate it. Thanks in advance!
-
Feb 15th, 2006, 07:16 PM
#7
Re: Combobox in a worksheet
Sorry for the delay, dont worry about the ActiveX combo box as its part of VBA so no other dependancies are needed that Excel doesnt already need.
I suggest using that one since its so similar to the VB 6 Combo box control.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 15th, 2006, 09:18 PM
#8
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
Thanks for the reply, how about the sample code I was asking, can you give me a code I can start with. Thanks again.
-
Feb 15th, 2006, 10:47 PM
#9
Re: Combobox in a worksheet
Adds 10 items to a ComboBox1 on Sheet1.
VB Code:
Option Explicit
Private Sub Workbook_Open()
Dim i As Integer
For i = 1 To 10
Workbooks(1).Sheets("Sheet1").OLEObjects("ComboBox1").Object.AddItem "Item " & i
Next
End Sub
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 16th, 2006, 03:56 AM
#10
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
I have managed to insert a combobox on the sheet then pasted your code on Workbook_Open event and got this error: Application-defined or object-defined error
-
Feb 16th, 2006, 04:05 AM
#11
Re: Combobox in a worksheet
Does your combo box reside on "Sheet1" and the cbo is named "ComboBox1"?
Also, macros enabled?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Feb 16th, 2006, 07:26 PM
#12
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
Hi Rob!
Yes is the answer to all your question. I had solved it now and I'd like to know why do I have to save the workbook first to be able not to get that error? I'd prefer a technical explanation about that, something like an answer from "excel documentation".
Thanks so much
-
Feb 16th, 2006, 10:49 PM
#13
Re: Combobox in a worksheet
I just pasted my code into a new workbook and added a cbo then ran the workbook_open procedure and it populated just fine.
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Mar 1st, 2006, 08:01 PM
#14
Thread Starter
Hyperactive Member
Re: Combobox in a worksheet
I've created a new workbook wrote a simple debug.print code in Workbook_Open and nothing is happening, I really have to save it first for the code to run. Anyway, thanks a lot, you've been a great help, problem solved!
-
Mar 1st, 2006, 08:40 PM
#15
Re: Combobox in a worksheet
Although this is resolved; as an alternate you could use "Create List" for a select range, then dynamically add values. No CBO overhead. - Just a thought
-
Mar 1st, 2006, 10:07 PM
#16
Re: Combobox in a worksheet
Workbook_Open only runs upon the opening or a workbook. If you manually run my code in post #9 on a new unsaved workbook with a combo it populates it just fine. Maybe a bit more of when you need it populated?
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|