Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TugboatEng on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using VB forms to populate and reference excel cells

Status
Not open for further replies.

dhair29

Civil/Environmental
Joined
Jan 22, 2004
Messages
1
Location
AU
Hey,

I know that this may seem like a really stupid question but how do you get a value from a combo box which is on a VB form to go into the excel file that the form is associated to.

For example, a value is selected from a combo box on the VB form. I now want that value to appear in an excel sheet such that i can use it to run calculations etc.

Further to that, how do you then use a text box to look at a field in an excel table and display the value from the excel sheet?

Any help would be greatly appreciated.

Cheers

David Hair
JRa
 
Something like

1) Open the Excel spreadsheet
Set DataFileObj = GetObject("C:\DataFile.xls")

2) Put a value into cell A1
DataFileObj.Worksheets(1).Range("A1").Value = CellValue

2) Get a value from cell A1
CellValue = DataFileObj.Worksheets(1).Range("A1").Value


Did that help?
 
dhair29,

Set the ControlSource property to the linked cell address, e.g. "Sheet1!A1"
If you want a list of items from the spreadsheet to display in the ComboBox, set the RowSource property to the range address, e.g. "Sheet1!B1:B20"
Note that you can do this by VB code or by typing the appropriate references in the properties window (press F4) in the VB editor, when you have the userform displayed and the textbox/combobox selected.

Cheers,
Joerd

Please see FAQ731-376 for tips on how to make the best use of Eng-Tips.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top