Search Tools Links Login

Retrieve Excel Cell Values Easily


Visual Basic 6, or VB Classic

Retrieves Excel spreadsheet cell information based on a set of parameters sent to the function. It then sets the value of the variable assigned when retrieveing the information.

Original Author: Ryan Rentfro

Inputs

Row value, column value, and file path.

Assumptions

Object programming and undertanding of functions.

Returns

The value of the set cell

Side Effects

If you use this function to retrieve massive amounts of data it is best to have excel open when doing so. I have computated 7 years of stock values and then averaged all values retrieved from excel. It takes about 75% longer to retrieve information when excel is closed.

Code

Function getExcel(rowval As Integer, columnval As String, excelfile As String)
Dim excelSheet As Object 'Excel Sheet object
  
  'Create an instance of Excel by file name
  Set excelSheet = CreateObject(excelfile)
  mycell$ = columnval & rowval
  getExcel = excelSheet.activesheet.range(mycell$).Value
  'Retrieve the result using the cell by row and column
  Set excelSheet = Nothing  'release object
  
End Function

About this post

Posted: 2002-06-01
By: ArchiveBot
Viewed: 98 times

Categories

Visual Basic 6

Attachments

No attachments for this post


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.