GET ULTIMATE EXCEL

March 2, 2018

Changing A Cell’s Value In Excel VBA (Range Object Method)

[et_pb_section bb_built=”1″ next_background_color=”#000000″][et_pb_row][et_pb_column type=”4_4″][et_pb_text _builder_version=”3.0.105″ background_layout=”light”]

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:

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section][et_pb_section bb_built=”1″ admin_label=”You Might Also Like” _builder_version=”3.0.105″ custom_padding=”11px|0px|54px|0px” prev_background_color=”#000000″ global_module=”14500″][et_pb_row global_parent=”14500″ _builder_version=”3.0.105″][et_pb_column type=”4_4″][et_pb_text global_parent=”14500″ _builder_version=”3.0.105″]

You Might Also Like

[/et_pb_text][et_pb_blog admin_label=”You Might Also Like – Blog” global_parent=”14500″ fullwidth=”off” posts_number=”6″ include_categories=”72,73,45,71,46,1,51″ show_comments=”on” use_overlay=”on” _builder_version=”3.0.105″ header_font=”Playfair Display|700|||||||” header_font_size=”20″ header_line_height=”1.4em” body_font=”Poppins||||||||” body_font_size=”16px” body_line_height=”1.5em” meta_font=”Poppins|600||on|||||” meta_font_size=”12px” meta_text_color=”#edbb5f” meta_letter_spacing=”1px” meta_line_height=”2em” pagination_font=”Poppins|600||on|||||” pagination_font_size=”16px” pagination_font_size_tablet=”51″ pagination_text_color=”#edbb5f” pagination_letter_spacing=”1px” pagination_line_height=”2em” text_orientation=”center” animation_style=”flip” custom_css_content=”display: none;” show_content=”off” show_thumbnail=”on” show_more=”off” show_author=”on” show_date=”on” show_categories=”on” show_pagination=”on” background_layout=”light” /][/et_pb_column][/et_pb_row][/et_pb_section]

2 comments on “Changing A Cell’s Value In Excel VBA (Range Object Method)”

  1. Hello,
    Can I please ask a question?

    I have found a simple user forms in an accounting software which I want to replicate and improve. I believe it to be the best I have come across since it is clean and uncluttered and does a great job. Please, can you help to do this on an excel spreadsheet. I am 60+ years old and cannot use/hold a mouse or a pen as my hands shake a lot. In particular, I like the date entry where you can increase/decrease using +/- keys rather than spinner but not using the mouse unless you can use up/down or +/- keys and I like the splitting of expenses into categories which is great. I have seen many videos of yours – I find you very clever and wonder if you can help. If there is a cost then do let me know for my consideration.
    Thank you.

    1. Hi Bharat,

      We do have consulting services, but I may be able to also make a YouTube video to help with the up and down keys part. If you’re need more advanced consulting services or assistance with development tasks, I’m happy to help with that as well. Please visit http://excelvbaisfun.com/contact/ for more details. Thanks! Dan

Excel VBA Is Fun

We believe Excel is one of the most versatile programs out there - and learning to program and automate it makes you very valuable!

You can prevent wasted time and errors, speed up tasks and become indispensable to your organization. 

See how our trainees have gotten raises, promotions and bonuses using their Excel Automation skills while building real problem-solving programs in Excel!
LEARN MORE
Copyright © 2022 ExcelVbaIsFun
X

Forgot Password?

Join Us

0
    0
    Your Cart
    Your cart is emptyReturn to Shop
    linkedin facebook pinterest youtube rss twitter instagram facebook-blank rss-blank linkedin-blank pinterest youtube twitter instagram