How can I specify a cell to use as input and output? I am pretty new to VBA in excel :)
Printable View
How can I specify a cell to use as input and output? I am pretty new to VBA in excel :)
What are you trying to do here Tom, can you give me an idea of your project as I'm not sure what you're trying to achieve here.
Thanks
It's pretty simple, I'm just not very good at explaining. I want to get text from, and put text in a cell that I know the co-ords of.
ahhh, okay, there's 2 main ways of doing this, either using the Range object, or the Cells object. I personally prefer using the range as it's easier.
To run these, open Excel & add a button onto the spreadsheet. Double click onto the button to get to the code window & enter the following code.
Using the range, you specify the letter of the column & the row number, so the first cell is referenced as A1. This returns a value in a messagbox for you.VB Code:
Private Sub CommandButton1_Click() MsgBox Sheets("Sheet1").Range("A1").Value End Sub
The cells way works backwards, you specify a number for the row first, followed by a number for the column, both of these make up a reference to a cell - so the first cell will be referenced as 1,1. This sample places a value into the cell:VB Code:
Private Sub CommandButton1_Click() Sheets("Sheet1").Cells(1, 1).Value = "A Value" End Sub
Thanks alot Alex :)