Visual Basic Question

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
I am trying to learn visual Basic and i want to create a data base control ( on a form) that will get information from am excel spreadsheet. The books I have bought are very specific about getting info from an access data base but nothing about excel. Is this possible and if so is there anyone in here that might be able to help me?

Marty

D1A@aol.com
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result

anvil19

Board Regular
Joined
Nov 18, 2003
Messages
230
Hi Marty

Yes there are a number of ways to get data into a control in Excel. The easier way is to use the controls' RowSource property. Something like this :

Add a ComboBox control onto a userform and add this to the forms Activate Event...

Code:
Private Sub UserForm_Activate()
    Me.ComboBox1.RowSource = "Sheet1!Dates"
    Me.ComboBox1.Text = "Start!"
End Sub

This code adds the data from a range called "Dates". If you have a different range of values for each use of the form or if you have no named ranges at all then just substitute the "Sheet1!Dates" value for "A5:G5" for example.

The
Code:
Me.ComboBox1.Text = "Start!"
bit is just to add a first line to your list of values, but will fall away when you pick the first value from the list.


If the range of data is different each time then it may be best to add a dynamic reference to the range of values you are wanting to use, like so :


Select the cells you wish to use and run this macro...

Code:
Private Sub LoadCombo1()
    Dim c
    Dim i As String
    
    i = ActiveWindow.RangeSelection.Address
    
    For Each c In Range(i).Cells
    Me.ComboBox1.AddItem c.Value
    Next c
    Me.ComboBox1.Text = "Start!"
End Sub

Try That.

anvil19
:eek:
 

Fire_Chief

Well-known Member
Joined
Jun 21, 2003
Messages
640
Thank you for your response.

I understand how to do it when working with excel modules however I am trying to get it to work when using a data control in "VISUAL BASIC" not VBA. Can you help me with this?

Marty

D1A@aol.com
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,152,322
Messages
5,769,453
Members
425,548
Latest member
macjagger17

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