Tutorial Details
Downloadable Files: Excel File
Introduction to Programming Macros in Excel
First Steps
Getting and Inputting Data
Adding Logic to Macros
Loops
UDF- User Defined Functions
Speeding Up Macros
Security
Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Put Data into a Worksheet using a Macro in Excel

Add to Favorites
Author:

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

Notes

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.

  1. Create some data in the macro.
    8e93812c3566dfa8f8c79510aa3adc76.jpg
    Here, I set the variable mydata equal to some text.
  2. Enter the location of the cell where the data will go:
    97b17643d2f8dc4c43c9c60e9f1af836.jpg
  3. Type .Value after it
    22fed6fa7df9b0a2bc31567daea80067.jpg
  4. Set it equal to the variable that has the data that we want to go into that cell.
    2cb43f207a1d8f76d7188841044675fe.jpg
    You can see this was done using a simple equal's sign and the name of the variable.
  5. Go back to Excel, run the macro, and that's it!
    b27190e8b169e8b34f8f6e814ab67c69.png

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

0320dfea6e8cabca39c180200beae349.jpg

This macro gets the data from cell A1 and puts it into cell B3.

After you run the macro, Excel will look like this:

93b99ef7c95f0c7078648f12856ef46d.png

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


Downloadable Files: Excel File