Results 1 to 2 of 2

Thread: range

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2004
    Posts
    2

    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

  2. #2
    Don't Panic! Ecniv's Avatar
    Join Date
    Nov 2000
    Location
    Amsterdam...
    Posts
    5,343

    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:
    1. RowCount = oWorksheetExisting.Cells(1,1).End (xldown).Row

    To get the range (total) into a string
    VB Code:
    1. strRange = oWorksheetExisting.range(oWorksheetExisting.cells(2,1),oWorksheetExisting.cells(RowCount,1).address false,false


    Vince

    BOFH Now, BOFH Past, Information on duplicates

    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
  •  



Click Here to Expand Forum to Full Width