This is a weird problem I'm seeing in Excel
Say I have a named range MY_RANGE
which points to cell $A$1 (or A1)
If I then enter =MY_RANGE into cell A2 all looks good
If I then try to edit cell A2 I see =$A$1 rather than =MY_RANGE
If I enter =MY_RANGE on a seperate sheet in the same workbook
everything works as expected.
I'm guessing there may be some property on the sheet that controls this behaviour but I can't find it. The problem I'm having is that when I copy & paste the cell it copies the resolved reference rather than the named range
I've kind of figured out a solution...
I've written a macro to do the following
Copy the formula (as a string, so "=MY_RANGE") into a different sheet at the same relative location (so cell 3,3 on SheetA to cell 3,3 on SheetB)
Copy the cell on SheetB back to the Cell on SheetA
I still have absolutely no idea what is causing this odd problem but this is a reasonable workaround for me at the moment
Related
So i am currently using Visual Studio to create a application that takes info out of an excel sheet and then does some calculations on the data and then pushes back to excel.
This bit i have managed to do but the bit i am struggling on is using a 'Parameters' sheet. I want to be able to enter a formula into a cell in one sheet of the workbook and then paste that formula into another sheet but to have it updating,e.g. as the cells go down the formula changes like it would in excel. I used a manual work around by hard coding the formula and then having variable as the row number, however i want to be able to just change the formula in the excel sheet and then when the code runs it applies to the rest.
Currently i have tried saving the cell value/text into a variable and then making the new cells equal that variable, however this then applies the same identical formula to the whole of the column(All required rows).
What i am currently trying to do is paste the variable into the top row and then copy and paste that cell down to the last one,
I have tried making the variable a formula but it evaluates the formula before it is equal to the variable and therefore just sets all the new cells to the formula answer, so i changed the cell to be text instead which then meant the formula did appear in the new cell however it was the identical formula for all cells.
The copy code works as below
bjExcel.cells(rown, colval) = param1
objExcel.cells(rown, colval).copy
This is working fine
But when i use the below the paste won't work
Do Until rown = 10
objExcel.cells(rown, colval).copy
rown = rown + 1
objExcel.cells(rown, colval).paste
Paste is not a recognized with the error:
System.MissingMemberException: 'Public member 'Paste' on type
'ApplicationClass' not found.'
Could be you need to use PasteSpecial instead?
https://learn.microsoft.com/en-us/office/vba/api/excel.range.pastespecial
Depends on what you're using to interop with excel.
shWorkSheet.Range("C7:C7").Copy()
shWorkSheet.Range("V7:V7").PasteSpecial(Excel.XlPasteType.xlPasteAll)
I had a hard time formulating the title, but I'll explain better here.
What I want to do is use a VBA-macro that I'm activating from a button click to copy the data found in the range B13:E52 on sheet1 to the same range on sheet"B3", where B3 is found on sheet1 containing the sheet name I want to copy to. This dynamically updates depending on what item is chosen in a list.
I know how to create my button, copy between sheet etc but I'm having a hard time figuring out how to reference the target sheet name that's contained in B3 for the target in VBA.
with sheet1
.range("b13:e52").copy sheets(.range("b3").value).range("b13")
end with
If you are looking to copy only the vlaues (without the formats or formulas), then you can use :
With Worksheets("Sheet1")
Worksheets(.Range("B3").Value).Range("B13:E52").Value = .Range("B13:E52").Value
End With
New Excel VBA user here. I feel like I made a silly syntax mistake.
I am trying to copy some vertical cells in one worksheet, to horizontal cells in another worksheet.
Worksheets("Master").Range("D14:F14").Value = Worksheets("Temp").Range("B12:B14").Value
However, the above command seems to only paste the value of B12 to cells D14:F14. Is there a way to paste the cells of B12, B13, and B14 to D14:F14?
Use Application.Transpose():
Worksheets("Master").Range("D14:F14").Value = Application.Transpose(Worksheets("Temp").Range("B12:B14").Value)
Or PasteSpecial:
Worksheets("Temp").Range("B12:B14").Copy
Worksheets("Master").Range("D14").PasteSpecial xlPasteAll, , , True
If you only want values then the first is best. When transposing with PasteSpecial one must use the xlPasteAll. It will throw an error if one tries to paste values only with transpose as true.
This is one that's been killing me and I've tried almost every solution on the Internet.
Here's background. I have an HR model that has each department broken out on separate tabs. I want to run an extract from our payroll system each payroll run and send highlight any updates individually. If someone's title or salary or status changes, I want to have that called out by highlighting the cell.
Each tab uses an INDEX/MATCH lookup to the extract tab to pull in the current information. What I want is if any value changes or is new(new hire, for example), highlight the cells.
I've played with Worksheet_Calculate and Worksheet_Change to no avail. Worksheet_Change doesn't fire because I'm not making the change directly on the sheet and Worksheet_Calculate doesn't have the Target object for to reference. I've tried the following code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim updatedCell As Range
Set updatedCell = Range(Target.Dependents.Address)
If Not Intersect(updatedCell, Range("A:A")) Is Nothing Then
updatedCell.Interior.ColorIndex = 3
End If
End Sub
The range I actually need evaluated is A7:R104 but I've been trying to get anything to work when linked to another sheet.
This works fine if formula of target cell is pointing to another cell on same sheet. The moment you point to one on another sheet it doesn't work. I've tried most of the solutions on here with no success. I've even tried putting the Worksheet_Change on the extract sheet and see if I can trigger it that way with no luck.
Is there a recommended solution to triggering a change to a cell for a formula linked to another sheet?
so I just saw this post, I don't know if you've found the solution or are still looking, but:
if you select a cell in sheet 3, you can then go to the home tab, go to "conditional formatting" -highlight cell rules - more rules (at the bottom) - and "use formulas to determine which cells to format" and then put your cursor in the formula box. now, select a cell in sheet 1 (click the sheet1 tab, and click a cell) and you'll notice it should populate the address for sheet1, and the cell u selected. now type <> after that cells address, then select sheet2 and a cell. then click format, and choose a fill color. then ok. if you go to conditional formatting and manage rules it will show there the rule / formula and which cells it applies to.
doing this i was able to select cell D10 in sheet 3, and make it an ugly green if cells in sheet1 and 2 didnt match (I picked which cells) you can also select a range of cells.
thusly, you can apply this rule to whatever dells you want, and if you record a macro of you setting this conditional formatting, you can manitpulate that macro to apply it to a bunch of different cells, and change the ranges. (using loops / variables)
Say I had two Excel sheets (ONE.xlsx & TWO.xlsx). Would it be possible to have a certain cell in ONE to be changed at the same time as a certain cell in TWO?
For example:
B2 in ONE is equal to "Tuesday". Is there a way to make D10 in TWO also equal to "Tuesday" without having to go into TWO and manually changing it.
The more I think about this problem the more I think that it's not likley to work. The only way I can think of it working is by connecting them both up to the same database somehow. Thought I'd try you guys before I give up try something else.
Thanks in advance!
I've found a solution that works very well.
Open both the workbooks.
In the source workbook, copy the cell(s) that you wish to link.
In the destination workbook, right click and select "Paste Link".
The cells in the destination workbook should now be linked so that when changes are made to the source workbook the changes are also made in the destination workbook.
Sure, open both workbooks.
put = in workbook 2 minimize and find the sheet/cell in workbook one
select it.
close workbook 2 and save.
change the value in workbook 1
open workbook to (enable the security to look at workbook 1)
see the updated value.