Results 1 to 3 of 3

Thread: Select sheet in Excel without knowing the name.

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Minneapolis, MN
    Posts
    189

    Select sheet in Excel without knowing the name.

    I can't seem to get this to work. I want to manipulate data on an Excel sheet and I don't know the name of the sheet. If I rename the sheet to "Sheet1" it works fine but otherwise no.

    This reports the name correctly:

    VB Code:
    1. Print objExcel.ActiveSheet.Name

    But then this code doesn't work:
    VB Code:
    1. i = 1
    2. Do
    3.    GetCount = .Cells(i, 2)
    4.    i = i + 1
    5. Loop Until GetCount = ""

    It says method "Cells" failed. As you can see, I'm trying to find out how many data points are in a column, if someone has an easier way...

    The test data I have currently only has one sheet, what if I had more than one?

  2. #2
    Member Matias's Avatar
    Join Date
    Jun 2005
    Location
    Buenos Aires, Argentina.
    Posts
    43

    Re: Select sheet in Excel without knowing the name.

    VB Code:
    1. i = 1
    2. Do
    3.    GetCount = .Cells(i, 2)
    4.    i = i + 1
    5. Loop Until GetCount = ""


    Try objExcel.ActiveSheet.Cells(i,2) instead of .cells(i,2)
    ... and the rivers shall open for the righteous, and the rivers shall open for the righteous, and rivers shall open for the righteous, someday ....

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Aug 2001
    Location
    Minneapolis, MN
    Posts
    189

    Re: Select sheet in Excel without knowing the name.

    Quote Originally Posted by Matias
    VB Code:
    1. i = 1
    2. Do
    3.    GetCount = .Cells(i, 2)
    4.    i = i + 1
    5. Loop Until GetCount = ""


    Try objExcel.ActiveSheet.Cells(i,2) instead of .cells(i,2)
    OK, it works. But I've done quite a bit of Excel manipulation and never had to do it that way before, must be becasue of the ambiguous sheet names?

    Now what if I have more than one sheet? I may never, but might as well ask now just in case.

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