ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Reading Entire Range (https://www.excelbanter.com/excel-programming/310312-reading-entire-range.html)

Peter[_46_]

Reading Entire Range
 
I have multiple workbooks with one sheet in them named Sheet1.
There is only one column filled with data, 'A'
The rows in column A are filled with text data.
I never know how many cells are in column 'A'.

How do I create a loop that goes through the entire range?

Here is my code that doesn't loop:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel._Worksheet
Dim mytext1 As String


xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Open("C:\MyXLS.xls")
xlSheet1 = xlBook.Worksheets(1)

mytext1 = xlssheet1.range("A1").value 'I need all the values in A




xlBook.Close()

Tom Ogilvy

Reading Entire Range
 
Dim rng as Excel.Range
Dim cell as Excel.Range


set rng = xlSheet1.Range(xlSheet1.Range("A1"), _
xlSheet1.Range("A1").End(xldown))
for each cell in rng

Next

--
Regards,
Tom Ogilvy


"Peter" wrote in message
om...
I have multiple workbooks with one sheet in them named Sheet1.
There is only one column filled with data, 'A'
The rows in column A are filled with text data.
I never know how many cells are in column 'A'.

How do I create a loop that goes through the entire range?

Here is my code that doesn't loop:

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet1 As Excel._Worksheet
Dim mytext1 As String


xlApp = CreateObject("Excel.Application")
xlBook = xlApp.Workbooks.Open("C:\MyXLS.xls")
xlSheet1 = xlBook.Worksheets(1)

mytext1 = xlssheet1.range("A1").value 'I need all the values in A




xlBook.Close()





All times are GMT +1. The time now is 09:39 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com