Read One Cell and Copy to Another Only Upon Opening Spreadsheet - excel

I need to copy the data in cell c3 to cell i11 when I open my spreadsheet. I do not want i11 to change after this action until I reopen the spreadsheet.

You can set the code in the ThisWorkbook part of your projects. Select Workbook and Open or use the following code.
The working formula is the value you see me do below, but this can be achieved a number of way such as using Cells(3,3).Value. Additionally the way the sheet is referenced can vary. I put both the Activesheet reference and a explicit sheet reference, depending how your sheet is structured you may have to use one over the other, but choose one below and see how your sheet handles it and if adjustments are needed.
Private Sub Workbook_Open()
'Use one of these depending on how your sheet opens
ActiveSheet.Range("I11").Value = ActiveSheet.Range("C3").Value
Worksheet("YourWorksheetHere").Range("I11").Value = Worksheet("YourWorksheetHere").Range("C3").Value
End Sub

Related

Need to paste Input on multiple sheets Excel, vba

Problem with referencing back to sheet2I have a workbook with 37 sheets. Each sheet requires the user's name.
I have a inputbox for them to put in their name, however it only posts on the active sheet. I have tried referencing back to the cell it fills from the macro but it wont reference.
Here is the code
Sub Name()
Set wsDst = ThisWorkbook.ActiveSheet
Sheets(2).Range("B16").Value = inputbox("Please type your first name and last intial.", "Name")
End Sub
Now if I go to Sheet3 and try ='Sheet2!B16
that is exactly what shows in cell B16.
The main issue is that the user's name will not always be in B16
Sheet4 is B18.
I know this is probably an easy fix for most, however I am still learning all the syntax's and honestly have used codes others have posted and been able to edit them to my needs.

Force Excel Formula to Reference Current Workbook

I have a simple formula reference that I use in my workbook, however it gets complicated when I use another function that instantly opens my default worksheet and copies it over to my active workbook.
The problem is that the cells in this workbook reference another sheet in my default workbook. The sheet in that and all the other workbooks I am working on has the same name. It's "Form"
When I use my code to copy the sheet over, the cell automatically changes it's reference to include the previous workbook.
I want the formula to ALWAYS USE THE CURRENT WORKBOOK.
Here is what I use
=Form!B6
Here is what I end up getting when i drop the sheet
="filepath"Form!B6
Here is a way to copy a formula from one workbook to another with no changes:
Sub ytrewq()
Dim s As String
s = Workbooks("book2.xlsm").Sheets("Sheet1").Range("G8").Formula
Workbooks("temp.xlsm").Sheets("Sheet1").Range("H1").Formula = s
End Sub
The trick is to use INDIRECT(). For example:
=INDIRECT("Form!B6")

Copy and paste VBA

I am working on a project which needs a lot of copy and paste cells between work sheets in excel which are not in order .I could barely program VBA . I am thinking that if i can write a program (click or right click to copy to clip board and double click to paste in different work sheet) that could make my work faster .Please suggest me.
you could use an excel formula to copy from one sheet to another
follow the instructions on this site
http://ccm.net/faq/9795-transfer-data-between-excel-spreadsheets
it basically says to
in the target cell type +
then select the source worksheet
click on the source cell
then hit enter
these steps will make a copy of, for example, work sheet 1, cell A1 into work sheet 2 cell A1
the formula is as follows =+Sheet1!A1
I hope this is of some help to you
You have a few options here, but let me first explain one thing to you.
When you are copying and pasting cells, you are actually using the Microsoft clipboard which is rather memory intensive process, and while this is the go to default option you could just as easily just assign value to value which doesn't use the clip board.
No frills option:
Sub Copy_and_Paste()
Sheets("Your Sheet Name").Range("Your Range").Copy
Sheets("Your Destination Sheet Name").Range("Your Destination Range").Paste
End sub
Example No frills
Sub Copy_and_Paste()
Sheets("Sheet 1").Range("A1:A10").Copy
Sheets("Sheet 2").Range("B1:B10").Paste
' You don't have to paste them in the exact same range.
' Just make sure they are the same size.
End sub
Values option
Sub Value_to_Value()
Sheets("Your Destination Sheet Name").Range("Your Destination Range").value = Sheets("Your Sheet Name").Range("Your Range").value
End sub
Example Values
Sub Value_to_Value
Sheets("Sheet 2").Range("B1:B10").value = Sheets("Sheet 1").Range("A1:A10").value
End sub
Experiment with both to come up with the version you prefer.

Linking cells to each other; having cells update linked cells and vice versa

I have two ideas that could lead to more or less the same result.
I am trying to have similar cells or tables update themselves to whatever the most recent entry was in the linked system. For example, cell A1 is linked to cell B2 (in this system that I am trying to create). I would enter something like "1" or "Text" or whatever in A1 and the system would update cell B2 to whatever I entered in cell A1. However the opposite must work in the same manner. If I changed whatever in cell B2 to, say, "5", cell A1 would also display "5". Also, note that I have Excel 2013.
I need this to work with a cell or a table. So, getting to the possible solutions...
A subroutine in VBA that automatically updates all the linked cells or tables.
Some sort of mechanic unknown to me that uses VBA or another Excel aspect to do this, like a function or tool.
In your answer or solution, please be mindful to my inexperience with VBA. Thanks in advance.
You can try a worksheet change function:
Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = Range("A1").Address then
ActiveSheet.Range("B1").Value = ActiveSheet.Range("A1").Value
ElseIf Target.Address = Range("B1").Address then
ActiveSheet.Range("A1").Value = ActiveSheet.Range("B1").Value
End If
End Sub
Although this seems like it might create an infinite loop (the update from the change causes another change) it DOES work for me in Excel 2010..
There are other Worksheet functions you can try as well (e.g. Worksheet_SelectionChange)
This macro needs to be placed/entered as a WORKSHEET macro on the sheet where you desire to use it..it will not work in a Module.
To install:
1) Save your workbook as a macro-enabled file.
2) Close Excel, reopen file, and enable macro security
3) Type Alt-F11
4) In the project explorer view on the left, look for your sheet name. Double click it
5) In the code entry area on right (big window) paste the example code above
6) Return to your worksheet and try it.

How to Protect the sheet name not the entire sheet?

I need to protect the sheet name by preventing
any change to the sheet name, or
the sheet being deleted.
This must be done without protecting the entire sheet using the Protect Sheet or Protect Workbook options.
Is there any way to do this with VBA?
Right click the sheet tab that you wish to protect
View Code
Copy and paste in the code below
This code disables the delete control on the sheet (but not right click on cell) menu when the sheet is activated. The control is enabled when the sheet is de-activated
The code will also name the sheet "NameOfSheet" when the sheet is de-activated. This is a workaround to prevent the sheet being renamed
Private Sub Worksheet_Activate()
Application.CommandBars.FindControl(ID:=847).Enabled = False
End Sub
Private Sub Worksheet_Deactivate()
Application.CommandBars.FindControl(ID:=847).Enabled = True
Me.Name = "NameOfSheet"
End Sub
I don't think you can. What you can do, you can make a worksheet a very hidden one (accessible only from VBA) and in case of the deleted sheet, you can copy it and make a copy visible.
Would this approach work?
Select all cells in the sheet, then UN-lock all cells with "Lock
Cells" (yellow background of padlock turns white).
Write the name of the sheet in a (fixed or named) cell, then lock
this cell ONLY ("Lock Cells", padlock background turns yellow).
Then Protect workbook, but allow every action, except the first one
"Select Locked Cells".
The user can do everything except selecting the cell with the sheetname (and delete rows/columns).
Now write a VBA to compare the actual sheetname with the data in the protected named cell (or fixed reference e.g. A1).
Run this script either on every change (probably too much) or at least on close of
the workbook.
As long as the sheetname is always in the same cell (e.g. A1), you can then loop through all sheets, compare their name with the data in cell A1 and correct the sheet name if required.

Resources