Referencing a new inserted column Excel VBA - vba

I am trying to reference a cell in the below formulaes. 'AUA Summary'!$D$9 . Each time the macro runs a new column D is inserted.
The Problem: When the column is inserted my reference moves to **
'AUA Summary'!$E$9. How do I get to reference 'AUA Summary'!$D$9 even if a new cell is inserted using VBA. My formuleas are below.
=IF(ROUND((SUM('BLL UTADS'!$D:$D)-'AUA Summary'!$D$9)+
(SUM('BLL UTADS'!$E:$E)-'AUA Summary'!$D$15),2)=0,"OK",
"Balances don't tie on BLL UTADS to AUA Summary Sheet")
=IF((SUM('BLL Prestige'!$D:$D)-'AUA Summary'!$D$10)+
(SUM('BLL Prestige'!$E:$E)-'AUA Summary'!$D$16)=0,"OK",
"Balances don't tie on BLL Prestige to AUA Summary Sheet")
=IF((ROUND('AUA Detail'!$D$9+'AUA Detail'!$D$23-'AUA
Summary'!$D$11,1)+ROUND('AUA Detail'!$D$15+'AUA Detail'!$D$29-'AUA
Summary'!$D$17,1))=0,"OK","Check the Totals tie")
The issue is on the 'AUA Summary' Tab the reference keeps changing. I have tried a VBA recorder , but i keep getting the same issue.
Each of these formuleas will be in a Cell.

You can use Indirect()
For example
'AUA Summary'!$D$9
can be written as
INDIRECT("'AUA Summary'!$D$9")
This way even when the columns move, it will refer to the same cell.
The other way is to use Index
For example D9 in Excel 2007+ can be written as INDEX(1:1048576,9,4) or INDEX(INDIRECT("1:" & ROWS(A:A)),9,4) for any version of Excel

Related

VB.net copy and paste excel cell to elsewhere in the workbook

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)

Auto populating rows from another sheet conditional to a specific cell value

Hello i am trying to autopopulate rows from another sheet if a specific value if found in a specific cell. So far, i managed to do it manually by adding this line in Sheet #2 for each cell.
=IF(OR('Le 2250'!$C48="Nouveau locataire",'Le 2250'!$C48="Décès", 'Le 2250'!$C48="Retention"), 'Le 2250'!$B48,"")
I am trying to create a vba script that will generate each column in Sheet#2, and that will dynamically update regarding if i add a row in Sheet 1 or delete it.
Sheet1 is:
Sheet2 is:
Your help is appreciated
What your looking for is the INDIRECT function
As an example:
=CELL("contents",INDIRECT("Sheet1!B5"))
This always pick up the value in Sheet1 Cell B5, regardless of changes in Sheet1.
For more information: Excel INDIRECT Function
Edit: To directly answer the question with INDIRECT.
=IF(OR(INDIRECT("'Le 2250'!C48")="Nouveau locataire",INDIRECT("'Le 2250'!C48")="Décès"),CELL("contents",INDIRECT("'Le 2250'!B48")),"")

VBA copy WebTable to Excel

I have a macro, that opens IE and navigates to a webpage. So now on the webpage, there are multiple tables. I'm trying to copy the last one to the page in Excel for further calculations but it copies all the values from the whole table in a single cell.How do I get the code to split the text into cells? The columns will be fixed for each page, but the number of rows might vary.
Worksheets("temp").Range("A1").Value = ie.document.getelementsbytagname("Table")(32).innertext
Here is what I have used in the past:
Because the table will more likely have rows and columns (td,tr) you can not assign the whole data to a single Range/Cell.
The method I ended using was to copy the whole table to the clipboard and Paste it on Cell/Range A1.
Set clipboard = New MSForms.DataObject
clipboard.SetText ie.document.getelementsbytagname("Table")(32).outerHTML
clipboard.PutInClipboard
Worksheets("temp").Cells(1, 1).PasteSpecial
Edit: You will need to add the Reference to Microsoft Forms 2.0 Object Library

VBA code on Hidden Sheet

I am building a small piece of VBA code to update the pivot table automatically so that my chart gets updated. After recording the code, I created stored it in the vb script of the sheet.
Here is my code:
ActiveSheet.PivotTables("PivotTable2").PivotCache.Refresh
I do not want to show the sheet containing the pivot table. So I hide the sheet, and then the code fails to work.
Try changing ActiveSheet to Worksheets("WorksheetName")
So you'd have
Worksheets("WorksheetName").PivotTables("PivotTable2").PivotCache.Refresh
Using ActiveSheet means it performs it on the sheet that is currently selected, last I checked you can't have a hidden sheet selected ;)

Excel VBA loop through columns in range and copy columns

I am new to Excel VBA and need some help writing a macro.
From Worksheet1 of Workbook1 I need to copy each column of range D1:Z100, one at a time, and pasteValue it to cells B1:B100.
This triggers a calculation in Worksheet2 of Workbook1. Here I need to copy cells A1:B200 into a new workbook.
This new workbook is to be renamed with the text string in Worksheet1, cell B1. The new workbook is to be saved into the same folder as Workbook1.
The loop is then to continue with the next column from Worksheet1, and continue until all columns in the range have been treated this way.
I have used two days searching the net to find an answer without any luck....
Start the way most of us did:
Record new macro.
Manually perform all the steps you want to automate.
Stop recording.
Go to the Developer tab and inspect the auto-generated code.
Write your own VBA based on what you learn in Step 4.
You will have to figure out a few things on your own, or come back here and ask specific questions.