Subscribe for Weekly Tutorials
BONUS: subscribe now to download our Top Tutorials Ebook!
Put Data into a Worksheet using a Macro in Excel
How to input data into cells in a worksheet from a macro.
Once you have data in your macro and you do something with it, you need to be able to put it back into Excel so you can see it or store it.
This tutorial assumes that you have read and are familiar with the last tutorial: Get Data from the Worksheet into a Macro in Excel
Sections:
Putting Data from a Macro into the Worksheet
Putting Data from One Cell into Another Cell Using a Macro
Putting Data from a Macro into the Worksheet
Putting data into a cell is as simple as setting the value of that cell equal to the data.
(If you don't already know how to reference cells in a macro, click that link to learn about it.)
Let's put "This is my data." into cell A1.
- Create some data in the macro.
Here, I set the variable mydata equal to some text. - Enter the location of the cell where the data will go:
- Type .Value after it
- Set it equal to the variable that has the data that we want to go into that cell.
You can see this was done using a simple equal's sign and the name of the variable. - Go back to Excel, run the macro, and that's it!
As you can see, it is quite simple to put data into a cell; you only need to know the location of the cell and then set its value equal to something.
Putting Data from One Cell into Another Cell Using a Macro
If you don't need to do anything with the data in the macro, you can simply transfer it from one cell to another cell quickly and easily like this:
Range("B3").Value = Range("A1").Value
This macro gets the data from cell A1 and puts it into cell B3.
After you run the macro, Excel will look like this:
This follows the same format as above except that we get the data directly from another cell.
Notes
This is very simple but very important. When building more complex macros, you will always need to use simple features like the one explained in this tutorial.
Make sure to download the sample workbook attached to this tutorial so you can play around with the code and get used to using it.
Question? Ask it in our Excel Forum
Tutorial: Make a particular worksheet visible using a macro in Excel. This is called activating a wo...
Tutorial: Data Validation is a tool in Excel that you can use to limit what a user can enter into a...
Tutorial: How to take data from Excel and put it into a UserForm. This is useful when you use a form...
Tutorial: How to get the name of a worksheet in Excel using VBA and Macros and also how to store tha...
Macro: This macro adds a column chart to Excel. This is an easy to use macro that allows you to q...
Macro: Create a bar chart in Excel with this macro. You will be able to quickly and easily turn a...