Results 1 to 4 of 4

Thread: reading data on a workbook (resolved)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908

    reading data on a workbook (resolved)

    i have a excel workbook on and a button on one of the spreadsheet..how do i retrieve the data from a particuar cell fromthe click of the button? do i need to open up another instance of the spreadsheet?
    Last edited by Goh; Apr 26th, 2004 at 10:59 PM.

  2. #2
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    If the other workbook is open it would look like:
    Code:
    Mystring = Workbooks("MyWorkbook").Worksheets("sheet1").Cells(1, 2).Value
    Where in cells "1" represents the row, and "2" represents the column.


    You could go through a column by using something like:
    Code:
    For X = 1 to MyLastRow
        Mystring(X)  = Workbooks("MyWorkbook").Worksheets("sheet1").Cells(1, X).Value
    Next X
    Or you could go through a range like:
    Code:
    For X = 1 to MyLastRow
               For Y = 1 to 5
                    Mystring(X,Y) = Workbooks ("MyWorkbook").Worksheets("sheet1").Cells(1, X).Value
               Next Y
         Next X

    You could also do a set if you use it a lot:

    Code:
    Set DATASHEET = Workbooks("Book6").Worksheets("sheet1")
    mystring = DATASHEET.Cells(1, 2).Value

    Or you could just activate the Workbook for a second.....

    Code:
    Workbooks("Book19").activate
    Mystring = Cells(1,2).value
    Workbook("MacroWorkbook").activate
    Last edited by Garratt; Apr 26th, 2004 at 11:35 PM.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jan 2004
    Posts
    908
    wow! thanks for the reply!...

  4. #4
    Addicted Member
    Join Date
    Dec 2001
    Posts
    158
    Cool.

    I had an error in the second example and fixed it btw

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