Sunday, 15 June 2014

Assign VBA Macro (Adding two Numbers)

A question has been asked in an Interview that if you have to add two numbers in Excel what will be the methods will we use? Most of us will answer that either we can use sum formula or we can use auto sum functions.



Now what if Interviewer has asked to solve above situation via VBA. So answer should be YES and you can write a very simple macro by using VBA. Here we go with small Example

1) Enable Developer Tab
2) Click on Insert Button and Select one Button



3) Change the Text to "Add Numbers"



4) Select Add Numbers and click on View Code button under Control Ribbon




5) Now as per question we have to execute our event on Button Click so we will write our code on Button Click.

Sub Button1_Click()
Range("I9").Value = Range("I7").Value + Range("I8").Value

End Sub

Range is actually an object which represents the Cell and .Value represents the text of that range.



 So our solution is ready, change the value of first no and second no, click on button and your answer will be ready.

In next post we will learn about

1) Working on Business Validation 
2) Display of Warning Message

Keep Reading and Keep Calm

Sanjay
mesanjaybakshi@gmail.com


No comments:

Post a Comment