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

scroll through xls file??

Status
Not open for further replies.

vbpadawan

Programmer
Oct 8, 2002
28
0
0
US
I need help figuring out the end of an excel spreadsheet that I am opening through vb. I open it as:
Dim wkbOjb As Object

Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.GetFolder("C:\test\cust")
Set fc = f.Files
i = 1
For Each f1 In fc

Set wkbobj = GetObject("C:\test\cust\" & f1.Name)
a = wkbobj.Worksheets(1).Range("A" & i + 1).Value
b = wkbobj.Worksheets(1).Range("B" & i + 1).Value
c = wkbobj.Worksheets(1).Range("C" & i + 1).Value
Next f1

I would like to increment i to get all the values in the spreadsheet but do not know how to stop at the end. Please help. Thanks.
 
You might try using the .UsedRange property of the worksheet object.

wkbobj.Worksheets(1).UsedRange.Rows.Count
wkbobj.Worksheets(1).UsedRange.Columns.Count Good Luck
--------------
As a circle of light increases so does the circumference of darkness around it. - Albert Einstein
 
It looks like you're just trying to loop through a directory on your machine and pull the file names into excel. If this is the case try the code below:

-------------------------------------------------------
Dim m_FSObject
Dim m_Folder
Dim m_File
Dim m_Files
Dim iCnt

Set m_FSObject = CreateObject("Scripting.FileSystemObject")

Set m_Folder = m_FSObject.GetFolder("c:\Windows")
Set m_Files = m_Folder.Files

For Each m_File In m_Files
iCnt = iCnt + 1

With ThisWorkbook
.Application.Cells(1,iCnt) = m_File.Name
'change to .Application.Cells(iCnt,1) =...
'if you want the files to display in column A
End With

Next
----------------------------------------

If I misunderstood what you are trying to accomplish, I apologize.

Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top