|
-
Sep 9th, 2004, 10:10 AM
#1
Thread Starter
New Member
range
Hi im trying to automate the range of a worksheet due to the fact that a number of worksheets of different ranges will be fed in to the software im making, ive got the following code below but everytime i try to run i get an error stating that the range of the worksheet failed...does anyone have any ideas on how to fix this please? any help appreciated, thanks 
Dim RowCount As Long
Set oWorkbookExisting = oExcelExisting.Workbooks.Open(fName)
Set oWorksheetExisting = oWorkbookExisting.ActiveSheet
'reads total number of rows in excel file
RowCount = oWorksheetExisting.Cells(Rows.Count, "A").End (xlUp).Row
'for loop that generates a range problem
For Each Cell In oWorksheetExisting.Range(Cells(2, 1), Cells(RowCount, 11))
Next Cell
-
Sep 10th, 2004, 06:54 AM
#2
Re: range
Originally posted by fizz_uk83
Hi im trying to automate the range of a worksheet due to the fact that a number of worksheets of different ranges will be fed in to the software im making, ive got the following code below but everytime i try to run i get an error stating that the range of the worksheet failed...does anyone have any ideas on how to fix this please? any help appreciated, thanks
Dim RowCount As Long
Set oWorkbookExisting = oExcelExisting.Workbooks.Open(fName)
Set oWorksheetExisting = oWorkbookExisting.ActiveSheet
'reads total number of rows in excel file
RowCount = oWorksheetExisting.Cells(Rows.Count, "A").End (xlUp).Row
'for loop that generates a range problem
For Each Cell In oWorksheetExisting.Range(Cells(2, 1), Cells(RowCount, 11))
Next Cell
This assumes that the first column has no breaks in the list at all
VB Code:
RowCount = oWorksheetExisting.Cells(1,1).End (xldown).Row
To get the range (total) into a string
VB Code:
strRange = oWorksheetExisting.range(oWorksheetExisting.cells(2,1),oWorksheetExisting.cells(RowCount,1).address false,false
Vince
Feeling like a fly on the inside of a closed window (Thunk!)
If I post a lot, it is because I am bored at work! ;D Or stuck...
* Anything I post can be only my opinion. Advice etc is up to you to persue...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|