One of the most foundational things to learn about when using Excel VBA is how to change a cell value, so that you deal with with this blog post.

On the most basic level, all you have to do is open up the Visual Basic editor in Excel by going to the developer tab and clicking the visual basic editor button. I prefer to use a keyboard shortcut (Alt + F11) to open up the Visual Basic editor.

To create your first macro, you need to add a new module:

Then, when you’re in the new module, we need to create our first macro. We will call it test123 and hit enter.

Now, let’s add some meaningful code. To make A1 become equal to the value “Hello World!”, we need to use Range() to do it. Try this:

[cc lang=”vbscript” lines=”-1″ width=”100%”]
Sub test123()
Range(“A1”) = “Hello World”
End Sub
[/cc]

When we run the macro (F5), it will make the value change in the actual cell as if someone typed it! Awesome!

This was an example of using a String/Text, by surrounding it with quotes. Here are some other examples of data types you can put into cells:

[cc lang=”vbscript” lines=”-1″ width=”100%”]
‘Text Format
Range(“A1”) = “Hello World”

 

‘Date Format
Range(“A2”) = #12/25/2018#

‘Number Format
Range(“A3”) = 250
[/cc]

For more info, check out this video to help you further:

You Might Also Like

Create Sheets For Each User From Column A

Create Sheets For Each User From Column A

Sometimes in Excel, we need to automate simple tasks, like to create sheets automatically for each item in a range. If you just had a few worksheet tabs that needed to be created, it wouldn't be a big deal, but what if you had to create 100 different worksheet tabs?!...

How To Add A Date Picker Calendar in Excel VBA

How To Add A Date Picker Calendar in Excel VBA

Date Picker Calendar in Excel VBA Oftentimes, users want to click a button and select a date. This is no different for Excel developers. Check out this ActiveX control by Microsoft that allows users to do just that. It's a little old school looking, but actually has...

X

Forgot Password?

Join Us