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?
Printable View
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?
If the other workbook is open it would look like:
Where in cells "1" represents the row, and "2" represents the column.Code:Mystring = Workbooks("MyWorkbook").Worksheets("sheet1").Cells(1, 2).Value
You could go through a column by using something like:
Or you could go through a range like:Code:For X = 1 to MyLastRow
Mystring(X) = Workbooks("MyWorkbook").Worksheets("sheet1").Cells(1, X).Value
Next X
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
wow! thanks for the reply!...:)
Cool.
I had an error in the second example and fixed it btw