OzGrid

How to use VBA to enter formula to a cell without activating the sheet

< Back to Search results

 Category: [Excel]  Demo Available 

How to use VBA to enter formula to a cell without activating the sheet

 

Requirement:

 

The user has a sheet (worksheets(1)) that will deactivate when selected.  The user would like to enter a formula to worksheets(1).range L1, which is "=worksheets(2)!L1" , how can the user get this with VBA?

 

https://www.ozgrid.com/forum/forum/help-forums/excel-vba-macros/148845-vba-to-enter-formula-to-a-cell-without-activating-the-sheet

 

Solution:

 

Code:
Private Sub Worksheet_Deactivate()
    Worksheets(1).Range("L1").Formula = "='" & Worksheets(2).Name & "'!L1"
End Sub

 

Obtained from the OzGrid Help Forum.

Solution provided by rory.

 

See also: Index to Excel VBA Code and Index to Excel Freebies and Lesson 1 - Excel Fundamentals and Index to how to… providing a range of solutions and Index to new resources and reference sheets

 

See also:

How to create new workbook by copying rows from multiple sheets based on value in column A
How to copy a sheet and rename from a list, ignore duplicates
How to extract information from a spreadsheet
How to use VBA code to copy Active Row cells to another sheet

 

Click here to visit our Free 24/7 Excel/VBA Help Forum where there are thousands of posts you can get information from, or you can join the Forum and post your own questions.


Gallery



stars (0 Reviews)