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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Read range from excel into VB program 1

Status
Not open for further replies.

uprichard

Programmer
May 2, 2002
16
I have a workbook that has a number of sheets that each contain named ranges. I want to be able to pull out all the data that is contained within a given named range.

I use the following to return a single cell

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSh As Excel.Worksheet
Set xlApp = CreateObject("Excel.Application")
Dim strCellContents As String
Set xlBook = xlApp.Workbooks.Open("c:\my_book.xls")
strCellContents = xlBook.Worksheets("svo_test_01").Range("A1").Value
xlBook.Close savechanges:=False
xlApp.Quit
Set xlApp = Nothing
Set xlBook = Nothing

How can I return all the values for a named range?
 
this will loop through a named range named "DataRng" and display the value of each cell.
Code:
For Each c In Range("DataRng")
   MsgBox c.Value
Next c

Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top