Copy paste values in Excel multiple selections - excel

I have tried to make multiple selections in an excel sheet where there are formulas in each cell that is highlighted as shown below. I have tried copy/paste these cells, so they only show hardcoded values instead of formulas. Unfortunately, Excel doesn't allow this type of action when you have multiple selections. Is there a way to have multiple selections (as shown below) in Excel and copy only the selected cells and then paste the values with only having to use the paste special option once?

I don't think there is any other way than using VBA in this case.
This code worked for me:
Sub myPasteSpecial()
Dim cell As Range
For Each cell In Selection
cell.Value = cell.Value
Next cell
End Sub

Related

How to clear paste range after Excel VBA copy and paste?

I use Application.CutCopyMode = False to clear the Copy range, but the Paste range is still selected. I hate leaving large ranges selected, so usually I'll just do something like "Range("A1").Select".
But that doesn't work if the target for the paste isn't on the selected sheet, so now I have to select the sheet before selecting another cell. I think all that is tacky. There must be a better way to deselect the Paste range, isn't there?

Excel conditional formatting using ADDRESS function

In my excel file you can make changes to the content. The cells which are changed should be marked with a different styling (different background color).
I thought i could solve it like
Create 2 worksheets with the same content
Create a conditional formatting condition. When the value of Cell A on Sheet 1 is different from the value of Cell A on Sheet 2, the formatting rule fires and the background color is changed.
This does work, for 1 cell. However, I would like it to apply on the entire sheet. The only way that i can make it work for now is to create a formatting rule for each cell which takes a lot more time (in EPPlus, C#).
I tried an unequal to condition like 'Sheet2!B2'. Can i make this function dynamic? Calling the ADDRESS function does not seem to work in this condition.
I would like to generate the sheet using EPPlus
Have you tried first removing the '$' signs in the conditional formatting formula for A1 and then selecting the entire sheet in 'Applies to' in the Conditional Formatting dialogue - in that order (if that can be done from EPPlus).
But it might be worth considering a completely different approach that does not require a copy of the sheet. I would add a Worksheet.Change event to the workbook module 'ThisWorkbook':
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
Target.Interior.ColorIndex = 4
End Sub

macro to use active cell and copy multiple cells to another sheet in different cells

I am trying to copy info from one sheet into another using a macro. I'd like to be able to select a cell in Sheet A (eg A10), and using that as a reference copy cells in the same row, eg c10, d10 and g10, and paste that info into static cells in Sheet B, eg $A$6, $A$7, and $A$8.
Have looked through the message boards but haven't found anything that uses the active cell, and multiple cells.
Thanks in advance!
Adrian
The task can be completed using simple statements like the following sample:
Worksheets("Sheet A").Range("A10").Copy destination:=Worksheets("Sheet B").Range("$A$6:$A$8")
In case you want be able to select a cell in Worksheets("Sheet A") and copy it to the destination Range (as shown above), then you may create a Sub like the following one:
Sub PasteSelection()
Selection.Copy Destination:=Worksheets("Sheet B").Range("$A$6:$A$8")
End Sub
and call it using, for example, ALT+F8 shortcut to run the Excel VBA macro.
Hope this may help.

Change variable from multiple sheets?

I have an excel workbook with multiple sheets that aggregate costs and revenues of different technological components (set up in different sheets) in a system.
I want to have a main worksheet, where users can change a small selection of important variables from the technology sheets. I also want those important variables to be defined and editable on the technology sheets.
I've been using named ranges to manage variables, but I'm not sure how to link two cells on different sheets to one variable. For example, I want to name a variable "oilprice" that is referenced in different formulas. I want to be able to change the variable "oilprice" from the main worksheet and the electricity technology sheet in my workbook.
Similarly, I want to be able to check a box on both sheets for "Turn on Electricity" and have the checkbox on the other sheet change as well.
I've been looking around on google and stackoverflow but can't find an answer. Thanks!
Named range, option 1: "override" style formula
With named ranges, you are not able to update the value from multiple cells. You could use logic in a formula to look at a "override" cell and pass that value to the actual named range. This works if the number of overrides is small. That style of formula looks like:
=IF(ISBLANK(oilprice2), oilprice1, oilprice2)
Where oilprice1 and oilprice2 are the cells that hold possible values. Note that there is an implied order in these which can get confusing after a while. That is, if oilprice2 has a value, it will not change oilprice1 nor will oilprice1 be considered.
Named range, option 2: scroll bar or spin control
Another option similar to the checkboxes below, is to use a spin control or scrollbar control to update the values. Those work across multiple sheets.
Checkboxes across sheets
For the checkboxes, this is handled by the Cell Link. You can set as many checkboxes as you want to control a single cell's value.
Here is an example with two checkboxes sharing the same Cell Link = $C$2. They both change when one is clicked.
Okay, I figured out how to have two cells to refer to the same value.
I named a range "oilprice" on the "electricity" sheet.
The cell to input oilprice on the "main" sheet has the formula "=oilprice" and is named "oilprice2", showing the value on the "electricity" sheet "oilprice" named range.
Then I made the following vba code which updates the "oilprice" cell on the electricity sheet when you change the "oilprice2" cell on the main sheet and reverts back to the formula showing "oilprice":
Private Sub Worksheet_Change(ByVal Target As Range)
If Not Intersect(Target, Target.Worksheet.Range("oilprice2")) Is Nothing Then
Application.EnableEvents = False
Worksheets("electricity").Range("oilprice").Value = _
Worksheets("main").Range("oilprice2").Value
Worksheets("main").Range("oilprice2").Value = "=oilprice"
Application.EnableEvents = True
End If
End Sub

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.

Resources