How To: Input values & formulas into a cell in Excel macros

Input values & formulas into a cell in Excel macros

This video shows how to enter values into cells using Excel macros and Visual Basic. This includes a sample Expense Report that is used in this demonstration. In this demonstration, we will create the macro that inputs a title as "Expense Report", Three columns i.e. "Date", "Item" & "Amount", and the summery field as "Total Expenses", as well as the formulas located at the respective cells. Now, we're going to use two keyboard shortcuts i.e. "Alt + F11" to open-up the VBA window and "Alt + F8" for viewing macros. Now, first we'll start with the VBA window, go to insert menu and select module to open the module window, and add the new Values_Input() module to create the Expense Report through the macros. Now, to input the values into the cells, we use the range object i.e. Range("A1").Value, to assign the value to the cell. Then with the "Equal to" sign, we'll write with quotation "Expense Report". Then in the next line again do the same practice for "Date", "Item", "Amount" and "Total Expenses" columns, by giving the cell number and values to that cell. Then in next line, we need to give a formula for the "Total Expenses" column, i.e. "=SUM(C:C)" as we need to sum the entire "Amount" column and give value to "Total Expenses" column. Now, as our macro is ready to be used, we'll delete every thing from cell "A1" to "F3". Then, using the shortcut "Alt + F8", select the macro from the list and Run. Every thing is back as it was before. Now, in order to link/assign one cell value to another, we need to define the column range (e.g. "E4:E6") instead of a particular cell number and assign its value by formula (e.g. "=C4"). Then, run the macro again, and you'll see that the values in column "C" are assigned to its respective cell in column "E". However, if you put the dollar sign ($) in the formula reference (i.e. "=$C$4"), it will not update the cells, because it will consider it as absolute reference values. So, that's how we can enter values into the cells using macros.

Just updated your iPhone? You'll find new features for TV, Messages, News, and Shortcuts, as well as important bug fixes and security patches. Find out what's new and changed on your iPhone with the iOS 17.6 update.

Be the First to Comment

Share Your Thoughts

  • Hot
  • Latest