VB icon

Retrieve Excel Cell Values Easily

Email
Submitted on: 1/16/2015 6:18:00 AM
By: Ryan Rentfro (from psc cd)  
Level: Advanced
User Rating: By 7 Users
Compatibility: VB 5.0, VB 6.0, VBA MS Excel
Views: 636
 
     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.

 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Retrieve Excel Cell Values Easily
' Description: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.
' By: Ryan Rentfro (from psc cd)
'
' Inputs:Row value, column value, and file path.
'
' Returns:The value of the set cell
'
' Assumes:Object programming and undertanding of functions.
'
' 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.
'**************************************

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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.