{"id":12142,"date":"2012-06-10T10:05:04","date_gmt":"2012-06-10T10:05:04","guid":{"rendered":"http:\/\/www.learnexcelmacro.com\/?p=1821"},"modified":"2022-08-12T11:17:46","modified_gmt":"2022-08-12T11:17:46","slug":"excel-macro-tutorial-basics-fo-vba-basic-syntaxes-required-while-coding","status":"publish","type":"post","link":"https:\/\/vmlogger.com\/excel\/2012\/06\/excel-macro-tutorial-basics-fo-vba-basic-syntaxes-required-while-coding\/","title":{"rendered":"Excel Macro Tutorial : Basics of VBA (Basic Syntaxes required while coding)"},"content":{"rendered":"
Let’s take a brief recap of all things you have studied so far in Excel Macro Tutorial.<\/p>\n
So far you have learnt so many basic stuffs about Excel Macros under Excel Macro Tutorials<\/a>. You have learned about all the Controls available in Excel Macros and also how to use them. You have also learned How to Record and Run a Macro in Excel. You also have learnt some basic Programming Lessons as well like If Else Statements<\/a>, For Loop<\/a>, While and DO While Loops<\/a> etc.<\/p>\n So far we have studied all the basic stuff about Excel Macro, which will be required for you to start developing a tool in Excel Macro. This is the most frequently used stuff in excel macro. Reading and writing the data in excel cells. Here are the simple syntax to do so.<\/p>\n Cells(<\/strong><Row Index> , <Column Index><\/i>).Value = <\/strong><Your Value><\/i> 1. Open a New Workbook Enter Value in Cell<\/p><\/div>\n In the above example as you saw that Command button will put the value in specified cell in the same worksheet where Command button is located. Under the Command Button Click Event Paste the below Code:<\/p>\n Below is the Syntax to select a Particular Worksheet from the Workbook.<\/p>\n Below is the Syntax to Activate a Particular Worksheet from the Workbook.<\/p>\n Let’s take a brief recap of all things you have studied so far in Excel Macro Tutorial. So far you have learnt so many basic stuffs about Excel Macros under Excel Macro Tutorials. You have learned about all the Controls available in Excel Macros and also how to use them. You have also learned How […]<\/p>\n","protected":false},"author":45,"featured_media":242487,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_et_pb_use_builder":"","_et_pb_old_content":"","_et_gb_content_width":"","footnotes":""},"categories":[1679,1676,5204],"tags":[],"class_list":["post-12142","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-excel-macro-beginner","category-excel-tips","category-vba-programming"],"yoast_head":"\n
\nHere I have collected a Set of questions or doubts, which are asked as soon as you start coding your own.<\/p>\n
\n1. How to read or Write some value in an Excel Cell?
\n2. How to read or write something in an Excel Cell of a Specified Sheet of the same Workbook.
\n3. How to Select a Worksheet from the Same Workbook?
\n4. How to Activate a Worksheet from the same Workbook?
\n<\/font>\n<\/div>\n1. How to put some value in an Excel Cell ?<\/h3>\n
\nOR<\/strong>
\nRange(<\/strong><Column Name><Row Index><\/i>).Value = <\/strong><Your Value><\/i>
\n <\/p>\nSteps to Do:<\/h2>\n
\n2. Add a Command Button to WorkSheet (How to Add Command Button in Excel<\/a>)
\n3. Double Click on the Command Button
\n4. Copy and Paste the Below Code in the Command Button Click Event<\/p>\n\r\nPrivate Sub CommandButton1_Click()\r\n Range(\"C3\").Value = \"Range C3\"\r\n Cells(4, 3).Value = \"Row No: 4 Column No: 3\"\r\nEnd Sub\r\n<\/code><\/pre>\n
\nNote: In the above you can see that no where Sheet Name is not mentioned. But as you know one Excel Workbook can have many Worksheets and in each worksheets the above Cell Address will exist. Since there is no Sheet Name mentioned, Code will put the value in the Same Sheet where your code or Your Command Button is there. <\/strong><\/font>
\nOn Clicking on Button, Cell C3 and C4<\/strong> will be populated with the Values. Refer the below diagram.<\/p>\n3. How to read or write some thing in a Excel Cell of a Specified Sheet of the same Workbook.<\/h3>\n
\n
\nLet’s take an example, you want to put this vale in Same Cell Address but in a Sheet named “MyData”. It means when you click on Command Button, it should Sheet named “My Data” and put these values in that particular cell of that Sheet. <\/p>\nFollow the below Steps:<\/h3>\n
\r\nPrivate Sub CommandButton1_Click()\r\n Worksheets(\"My Data\").Range(\"C3\").Value = \"Range C3\"\r\n Worksheets(\"My Data\").Cells(4, 3).Value = \"Row No: 4 Column No: 3\"\r\nEnd Sub\r\n<\/pre>\n
\nNote: <\/strong> Above code will through error if the Sheet Name does not exist in that workbook.
\n<\/p>\n3. How to Select a Worksheet from the Same Workbook ?<\/h3>\n
Worksheets(\"Sheet Name\").Select<\/pre>\n
4. How to Activate a Worksheet from the same Workbook ?<\/h3>\n
Worksheets(\"Sheet Name\").Activate<\/pre>\n
\nTo Check out more Excel Tips and Tricks, visit Excel Tips and Tricks<\/a><\/strong>\n<\/div>\n<\/span>","protected":false},"excerpt":{"rendered":"